Tuesday, January 8, 2019

Bash scripts on command line not in a file

There are situation as a Linux System Administrator or related roles, we need to write a quick shell script on the command line instead of putting it in a file. When we actually use semicolon to delimit commands. However, in a bash file, we actually use "carriage returns" (Enter button) to separate commands. For example:

 For example, this is the command on the command line:

$ for i in `seq 5`; do if [[ $i == 3 ]]; then echo "number is $i"; fi;  done

number is 3

No comments: