When above I defined the variable "a", the command cat emp.lst was not quoted and hence variable "a" should not have accepted a newline character.
Variable assignments bypass field splitting and pathname expansion (aka file globbing). IFS is irrelevant.
Since double quotes prevent field splitting and pathname expansion from occurring (the only sh parsing steps which can increase the number of elements in a command line), a="`cat emp.lst`" is equivalent to your unquoted version.
The newlines that you mention are in $a. The difference you observe is a result of quoting or not quoting echo's argument. The newlines are consumed by field splitting when the shell parses echo $a. The difference between the two echo commands is that in the quoted version, the shell is invoking echo with one argument, which contains three lines of names. In the unquoted version, the shell itself looks at the contents of $a, splits it on whitespace, consuming the newlines and (this is important) the spaces as well. echo is then invoked with 6 arguments, one for each word of the names. It is echo's job to then take its 6 arguments, join them with a single space between each, and print the result. In the quoted version, since echo is only passed a single argument, it does not add any space characters.
Note that command substitution always strips trailing newlines (not embedded). This has nothing to do with quoting, field splitting, IFS, nor variable assignment. It's how command substitution is designed. You may not have noticed that because echo, besides joining its arguments with a space character, appends a newline. If, however, your file has multiple newlines at the end, you will notice that when you echo the contents of a double-quoted $a, only a single newline is present (all trailing newlines were stripped by the command substitution but only one is added by echo).
I'm having some peculiar performance issues with my Gigabit Lan.
I have some 100Mb devices so I can't do the necessary "jumbo Frame" tweaks for absolute optimum performance as I'd prevent them access.
I'm getting appauling transfer rates sending files to the linux machine, around 10 Mbps 3%... (0 Replies)
Whenever I sftped a particular gzipped file to a particular directory and then try to unzip it, I get Permission Denied error.
With this file even I cannot do chmod. though the file permissions are -rw-r--r--
When same file I sftp to a different location I am able to gunzip it.
Directory... (0 Replies)
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)
Scenario:
Step 1. I'm logging into AIX server using user id called user1
Step 2. I'm traversing to home directory of user2
Note: This user2's home directory has the permissions drwxr-s---
Step 3. I'm issuing command pwd there. I'm getting the expected output.
Step 4. I'm issuing the... (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)