unix - Trying to return a simple echo statement -
i want output "you have not entered file".
if user literally inputs nothing after calling unix script, receive error message.
for var in "$@" file=$var if [ $# -eq 0 ] echo "you have not entered file" elif [ -d $file ] echo "your file directory" elif [ -e $file ] sendtobin else echo "your file $file not exist" fi
i cannot figure out wrong, believe it's in first if statement
i rewrite this:
#!/bin/bash if (( $# == 0 )); echo "you have not entered file" else file in "$@"; if [ -d "$file" ]; echo "your file directory" elif [ -e "$file" ]; echo sendtobin "$file" else echo "your file $file not exist" fi done fi
important points:
the structure of script should first check if arguments passed. if there aren’t any, print appropriate message. otherwise handle each argument.
if ... else ...
.for arithmetic, use arithmetic evaluation. manual confusing can be used, can
if (( ... ))
, c-stylefor (( = 0; < n; i++ ))
.always wrap variables
$file
in quotes:"$file"
. if there simple space in filename, break otherwise.
Comments
Post a Comment