Confusion about IFS Variable


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Confusion about IFS Variable
# 1  
Old 03-04-2008
Lightbulb Confusion about IFS Variable

=================================================
#!/bin/sh
HOST=eux091
if [ -s /etc/maestab ] && grep -q $HOST /etc/maestab
then
IFS=:
grep -v -e "^#" -e "^$" /etc/maestab | grep $HOST | \
read HOST MAESTRO_BIN FLAG MAESTRO_USER
echo $MAESTRO_BIN
MAESTRO_HOME=`dirname $MAESTRO_BIN`
echo $MAESTRO_HOME
fi
=================================================
here is /etc/maestab

eul3p3:/opt/maes3p3/maestro/bin:Y:maes3p3

==================================================
script working fine with HP-UX but not in Linux, can you help me out where I am wrong.
# 2  
Old 03-04-2008
Dirname is part of coreutils Linux package.
Do you have the coreutils installed on your Linux system?

Regards
# 3  
Old 03-04-2008
Works for me using ksh on linux - provided you set HOST to a value that is in maestab
# 4  
Old 03-04-2008
CPU & Memory

Frank,

dirname works wihout issue.

fpm,

oops!! sorry, i have copied script from my hp-ux system and maestab from linux system. but actully I am paasing value of $HOST by $1 in my script.
pls read HOST=eul3p3 in this case.

Thanks.

Awadhesh

Last edited by Awadhesh; 03-04-2008 at 08:50 PM.. Reason: .
# 5  
Old 03-04-2008
A script like:
#! /bin/sh
echo hello | read word ; echo word = $word
will work on HP-UX but fail on Linux. HP's /bin/sh is a modified version of the real Korn shell. But Linux's /bin/sh is a linked version of bash. The real Korn shell is the only shell that executes the last command of a pipeline in the context of the current shell provided that the last command is a shell built-in. Other shells will fork a new process to handle that "read word". The subprocess will exit and back in the parent, the variable "word" never got a new value. Beware: Linux often has pd-ksh which will behave the same way.
# 6  
Old 03-05-2008
Tools Thanks!!

thanks, u always come with a torch.


pd-ksh is there, but i really dont know how to use it in script.

[root@eul3p3 tmp]# rpm -qa|grep -i pdksh
pdksh-5.2.14-30.3
[root@eul3p3 tmp]#

Awadhesh
# 7  
Old 03-05-2008
Quote:
Originally Posted by Awadhesh
.
pd-ksh is there, but i really dont know how to use it in script.
Well, considering that pd-ksh will fail in the same manner that bash does, I'm not sure that this is any great loss. But just use
#! /usr/bin/ksh
on Linux to invoke pd-ksh. I believe that the real ksh is available for Linux, but I don't know how you get it. You need to stop doing
some-command | read this that
to get your script to work with bash or pd-ksh. If you can't think of anything else,
some-command > tempfile
read this that < tempfile
rm tempfile
should do it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Odd Behaviour for Set and IFS variable

Ok, so I'm playing around with delimters and reading files. and I came across this behaviour that I thought was a bit odd, regarding how the set command takes values... If I run this: IFS=$'-' #Assigns the - as the default delimiter for bash set I-love-my-gf-a-lot #uses set to put a bunch of... (1 Reply)
Discussion started by: Lost in Cyberia
1 Replies

2. Shell Programming and Scripting

Not able to understand IFS

Hi , i am in my initial learning phase of unix. i was going thru the function part. below is the example which was there but i am not able to understand logic and the use of IFS(internal field separator) lspath() { OLDIFS="$IFS" IFS=: for DIR in $PATH ; do echo $DIR ; done IFS="$OLDIFS"... (8 Replies)
Discussion started by: scriptor
8 Replies

3. Shell Programming and Scripting

While loop and IFS?

Hi, while ; do echo "Please enter " read enter yyyy=${enter:0:4} mm=${enter:5:2} dd=${enter:8:2} result=`validateDate $yyyy $mm $dd` When does the loop keeping repeating till?? till 1 is equal to 1? what does this mean "${enter:0:4}" .The 0 and 4 part?? ... (3 Replies)
Discussion started by: sid22
3 Replies

4. Shell Programming and Scripting

little confusion about variable initialization.

Whenever i execute the below scriptlet with out proper file name it deletes /tmp directory . I guess this is because value of variable a didnt get initialized and there for rm -rf /tmp/ get executed and entire /tmp directory get deleted. How would i avoid any empty variables to be used in... (9 Replies)
Discussion started by: pinga123
9 Replies

5. Shell Programming and Scripting

regarding IFS=

hi i am a learner can some explain "export IFS=$(echo "\n\t\a")" i am not able to understand the functionality please help thanks Satya (1 Reply)
Discussion started by: Satyak
1 Replies

6. Shell Programming and Scripting

resetting IFS variable

Hi, I have modified the IFS variable in the K shell program and with in the program i want to reset to the default one. How do i reset the same. e.g in the begining of the program IFS is default in the middle i changed it to IFS="|" and again i want the default value for the IFS. ... (2 Replies)
Discussion started by: vijaykrc
2 Replies

7. UNIX for Dummies Questions & Answers

Help on IFS command!

Hi! I am working in korn shell. I want to reset the dimiliter for the set command to "|" but instead of a command prompt return I am getting something as below After issuing the command I am getting this....as if the shell is expecting something else. Can anybody suggest what's the problem. ... (2 Replies)
Discussion started by: udiptya
2 Replies

8. UNIX for Dummies Questions & Answers

IFS variable

How can I set the value for IFS variable (2 Replies)
Discussion started by: mahabunta
2 Replies

9. UNIX for Dummies Questions & Answers

the IFS variable

Hi all, Ok os heres my situation. I have created a database style program that stores a persons info (name,address,phone number etc.) in a file ("database"). after i read in all the values above, i assign them to a line variable: line="$name^$address^$phonenum" >> phonebuk as you can see... (1 Reply)
Discussion started by: djt0506
1 Replies

10. Shell Programming and Scripting

IFS changing the variable value

Hi, I have a while read loop that reads files in a directory and process. The files have spaces in between, so I have the IFS=\n to to read the whole line as one file name. The read works fine but I have a problem with another variable that I set in the beginning of the script. The variable... (1 Reply)
Discussion started by: pvar
1 Replies
Login or Register to Ask a Question