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-style for (( = 0; < n; i++ )).

  • always wrap variables $file in quotes: "$file". if there simple space in filename, break otherwise.


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 -