what I am saying is I have been told to do it differently in the format of:[...]
Did you ask him why he wants you to do so?
Quote:
I am unsure why exactly I must use OLDIFS, but I assume it's a problem with sh? so far all tests I have done using IFS in while loop in sh, ash, bash, ksh all seem to work fine... So I really have no idea why my tutor seems to think otherwise, would have been helpful if I asked him to expand on this..
There's a potential problem and it's not sh (Bourne Shell) specific. For instance, you may need the previous (most likely the default) value of IFS in case you need to use the shell word splitting latter in your script:
Quote:
I think the basic logic behind it is, 'sh' doesn't handle subshells very well, while bash/ksh etc do handle subshells fine.[...]
Not at all, I meant to use a sub-shell only to avoid affecting the current shell environment:
Quote:
Like I have already mentioned my problems using OLDIFS variable is that my constant variables that i use to echo statements to standard output are missing the n's[...]
I'm not sure if I understand what you're trying to say, but I suppose that you only need to quote your variables while echoing them:
Semi-right:
Right:
Often wrong:
By post the exact command(s)/output I mean that we need to see:
+ the exact content of the script/code you're executing
+ the exact content of any input/output files (if any)
+ the exact command as issued on the command line and all the output you're getting (if any)
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)
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)
Hi,
This is out of curiosity:
I wanted to extract year, month and date from a variable, and thought that combining read and IFS would help, but this doesn't work:
echo "2010 10 12" | read y m d
I could extract the parts of the date when separated by a -, and setting IFS in a subshell:
... (3 Replies)
Given the scenario like this, if at all if have to use IFS on the below given example, how it should be used.
IFS=/
eg:
/xyz/123/348/file1
I want to use the last slash /file1 . So can anyone, suggest me how to pick the last "/" as a IFS. (4 Replies)
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)
hi I keep getting an error with this nested if statement and am getting the error unexpected end of file, can anyone help me as to why this wont execute?
#!/bin/bash
#script to check wether the -i -v statements run correctly
removeFile ()
{
mv $1 $HOME/deleted
}... (3 Replies)
I am using bash and resetting IFS as below when reading the command line arguments. I do this so I can call my script as in Ex1.
Ex1: ./synt2d-ray3dmod.bash --xsrc=12/20/30
This allows me to split both sides so that when I do "shift"
I can get 12/20/30
What I do not understand is... (21 Replies)
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)