unix - echo "You have not entered a file" -


the problem want echo string "you have not entered file".

simply put, if user literally inputs nothing after calling unix script, receive error message.

here code

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 done 

i cannot figure out wrong, believe it's in first if statement

if user enters no arguments, $@ empty -- in other words, loop runs 0 times. check needs happen outside loop.

additionally, -d , -e checks, should quote "$file", otherwise if user entered empty string arg, unexpected behavior (it if no arg had been passed, , in case -d , -e end returning true).


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -