Checking for "*" as input

Posted on 2003-03-14
Medium Priority
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 *  ?
Question by:894359
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

Expert Comment

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

  and the same to the other variables

Author Comment

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!
LVL 84

Accepted Solution

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 *"
  echo "the first one is not an *"
LVL 48

Expert Comment

ID: 8141644
No need for cut -c1-1

cut -c1

is fine.

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