?
Solved

Checking for "*" as input

Posted on 2003-03-14
4
Medium Priority
?
255 Views
Last Modified: 2010-04-21
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 *  ?
0
Comment
Question by:894359
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 6

Expert Comment

by:bira
ID: 8140755
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
0
 

Author Comment

by:894359
ID: 8140842
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!
0
 
LVL 84

Accepted Solution

by:
ozo earned 500 total points
ID: 8140905
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
0
 
LVL 48

Expert Comment

by:Tintin
ID: 8141644
No need for cut -c1-1

cut -c1

is fine.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tech tip describes how to install the Solaris Operating System from a tape backup that was created using the Solaris flash archive utility. I have used this procedure on the Solaris 8 and 9 OS, and it shoudl also work well on the Solaris 10 rel…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
Suggested Courses
Course of the Month11 days, 11 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question