" exit 1 fi echo "$0 counts the lines of code" l=0 for f in $* do l=`wc -l $f | sed 's/^\(*\).*$/\1/'` echo "$f: $l" done Let’s say I’ve written this bash script to count the number of lines in a list of files, but want to expand this to do very tricky things based on the output: #!/bin/bash if then echo "Usage: $0 file. I’m going to use an artificially simple but realistic bash script to walk through a conversion process. With a little bit of effort you can quickly convert your bash script to a python one and move ahead. I created a Docker image to convert it, and have used it a couple of times. I found a bash2py tool, which looked good, but came as a zipped source download (not even in a git repo!). Generally I start with a bash script because it’s so fast to get going, but as time goes on I add features, and then wish I had started it in python so that I could access all the modules and functionality that’s harder to get to in bash. I routinely use both bash and python to quickly whip up tools for short and long-term uses. Use this Docker image to convert your script. Ever start a bash script, then wish you’d started it in python?
0 Comments
Leave a Reply. |