Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

Checking for "*" as input

If I am reading in a text file:

while read -r subdir_to_move subdir_to_make JUNK ; do

how do I check to make sure the first character of each variable is not *  ?
Avatar of bira
bira

if [ `echo $subdir_to_move|cut -c1-1` = "*" ] ; then
     echo "the first character of $subdir_to_move is an *"
   else
   echo "the first one is not an *"
fi

  and the same to the other variables
Avatar of MJ

ASKER

I get a weird error when testing your code! I get a:

./mk.sh[67]: findReplaceStatic.pl: unknown test operator

when ever the first character is an * and it still tests false as if the first character is not a *


Also note that for some reason it lists another script in the directory in the error? The script name I'm testing is mk.sh!
ASKER CERTIFIED SOLUTION
Avatar of ozo
ozo
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
No need for cut -c1-1

cut -c1

is fine.