Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


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

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 85

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

Independent Software Vendors: 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

A metadevice consists of one or more devices (slices). It can be expanded by adding slices. Then, it can be grown to fill a larger space while the file system is in use. However, not all UNIX file systems (UFS) can be expanded this way. The conca…
Java performance on Solaris - Managing CPUs There are various resource controls in operating system which directly/indirectly influence the performance of application. one of the most important resource controls is "CPU".   In a multithreaded…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
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…
Suggested Courses

571 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