?
Solved

Korn Shell script problem

Posted on 2003-03-21
6
Medium Priority
?
375 Views
Last Modified: 2010-04-21
I have a strange problem with a Korn shell script running on Digital UNIX v5.1:

for LINE in $(</home/sfdm/arvindk/sfcbom2.txt)
do
echo ${LINE}
done

The file I am reading has:

/home/sfdm/arvindk> cat sfcbom2.txt
[22222B]

If I run this I expect to see [22222B] in output but I see only 2:

/home/sfdm/arvindk> script1
2

On the shell prompt, some numbers work fine but some dont (using \ to escape does work for 32 and 31) -

/home/sfdm/arvindk> echo [44]
[44]
/home/sfdm/arvindk> echo [32]
2
/home/sfdm/arvindk> echo [31]
1

Any idea why this is happening?

Thanks
0
Comment
Question by:ashaarvind
[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
6 Comments
 
LVL 6

Expert Comment

by:bira
ID: 8183761
for LINE in  `cat/home/sfdm/arvindk/sfcbom2.txt`
do
echo $LINE
done
0
 
LVL 6

Expert Comment

by:bira
ID: 8183774
for LINE in  `cat /home/sfdm/arvindk/sfcbom2.txt`
do
echo $LINE
done
0
 
LVL 5

Accepted Solution

by:
ecw earned 100 total points
ID: 8183968
Have you got a file called 2 in the current dir?
use,
  for LINE in $(</home/sfdm/arvindk/sfcbom2.txt)
  do
    echo "${LINE}"
  done

not the double quotes around the var, this is to stop the shell using [] as special chars.

0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 51

Expert Comment

by:ahoffmann
ID: 8184186
use /usr/bin/echo or wherever you have a echo program instead of the shells built-in echo
also quote the variable (as in ecw's suggestion)
0
 

Author Comment

by:ashaarvind
ID: 8184497
The comment from ecw had the answer. There was a file called '2'in the same directory. It fixed my problem - but I am still puzzled on why this happened?

Thanks/Arvind
0
 
LVL 5

Expert Comment

by:ecw
ID: 8184625
It happened because [ and ] are used by the shell for matching a specfic set of chars during wildcard expansion.

For example
 [Aa]* will match all files beginning with an upper or lower case A
 [A-Z]* will match all files beginning with an upper case char
 *.[aeiou]* will match all files with a . followed by a vowel

The sense of the match is negated if the first char after [ is a ! eg.
 *.[!16-9] will match all files that don't end in .1 .6 .7 .8 or .9
Note the use of - to specify a range.

So in your example,
 echo ${LINE}
expands to
 echo [22222B]
Which is then subject to filename expansion, capable of matching a 'single' character filename of either 2 or B

You just happened to have a file called 2, so it matched that.  If you'd also happened to have a file called B, the output would've been
 2 B
Sounds like a pencil top me.
0

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

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…
Why Shell Scripting? Shell scripting is a powerful method of accessing UNIX systems and it is very flexible. Shell scripts are required when we want to execute a sequence of commands in Unix flavored operating systems. “Shell” is the command line i…
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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Suggested Courses

771 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