Shell script questions
70 shell script questions exec tempfile 1) How to pass argument to a script ? ./script argument Example : Script will show filename ./show.sh file1.txt cat show.sh #!/bin/bash cat $1 2) How to use argument in a script ? First argument: $1, Second argument : $2 Example : Script will copy file (arg1) to destination (arg2) ./copy.sh file1.txt /tmp/ cat copy.sh #!/bin/bash cp $1 $2 3) How to calculate number of passed arguments ? $# 4) How to get script name inside a script ? $0 5) How to check if previous command run successful ? $? 6) How to get last line from a file ? tail -1 7) How to get first line from a file ? head -1 8) How to get 3rd element from each line from a file ? awk '{print $3}' 9) How to get 2nd element from each line from a file, if first equal FIND awk '{ if ($1 == "FIND") print $2}' 10) How to debug bash script Add -xv to ...