Do you want BuboFlash to help you learning these things? Or do you want to add or correct something? Click here to log in or create user.



Question
In linux, write simple bash script that takes file name as command line argument, and prints out that file name ONLY if that file exists in the current directory (e.g. running "tests.sh test.txt" would print "yes" only if file test.txt exists).
Answer
#!/bin/bash

if [ -e $1 ]; then
   echo "yes"
fi
^^^ not the use of -e to check existance of file, recall $1 is used to access first command line arg

Question
In linux, write simple bash script that takes file name as command line argument, and prints out that file name ONLY if that file exists in the current directory (e.g. running "tests.sh test.txt" would print "yes" only if file test.txt exists).
Answer
?

Question
In linux, write simple bash script that takes file name as command line argument, and prints out that file name ONLY if that file exists in the current directory (e.g. running "tests.sh test.txt" would print "yes" only if file test.txt exists).
Answer
#!/bin/bash

if [ -e $1 ]; then
   echo "yes"
fi
^^^ not the use of -e to check existance of file, recall $1 is used to access first command line arg
If you want to change selection, open document below and click on "Move attachment"

7. Shell Scripting
file 10 times with 10 different extensions. As you can see, the variable $1 has a special meaning--it is the first argument on the command-line. Now let's get a little bit more sophisticated ( <span>-e test whether the file exists): 5 10 #!/bin/sh if test "$1" = "" ; then echo "Usage: backup-lots.sh <filename>" exit fi for i in 0 1 2 3 4 5 6 7 8 9 ; do NEW_FILE=$1.BAK-$i if test

Summary

statusnot learnedmeasured difficulty37% [default]last interval [days]               
repetition number in this series0memorised on               scheduled repetition               
scheduled repetition interval               last repetition or drill

Details

No repetitions


Discussion

Do you want to join discussion? Click here to log in or create user.