Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


$ cat lines.txt
'c/d e/f'

$ cat 1.sh
./2.sh `cat lines.txt`

$ cat 2.sh
echo p1=$1
echo p2=$2
echo p3=$3

$ ./1.sh

How do I change lines.txt or 1.sh, so that 2.sh receives only two arguments:

  • a/b
  • c/d e/f


share|improve this question
up vote 1 down vote accepted

Set the IFS (internal field separator) to a newline:

$ cat 1.sh 
./2.sh `cat lines.txt`

$ ./1.sh
p2='c/d e/f'
share|improve this answer

If you aren't locked into the idea of using cat to send as many args as the file is long, you may find this method quite flexible. You can pipe file directly to 2.sh

# echo -e "a/b\n'c/d e/f'" >lines.txt

fn2.sh() { set -f              # disable pathname expansion 
   while IFS= read -r line; do # -r prevents expansion of such things as \n
       printf "%s\n" "$line"   # printf is more robust than echo (when dealing with unknown data)
< lines.txt fn2.sh             # using redirection 
share|improve this answer
The real file contains about 60 lines. So, I cannot just list them on the command line. – mark Aug 25 '11 at 9:50

If your input file contains the line 'c/d e/f' and you want to process the item c/d e/f (without the quotes), then you may be looking for xargs. Its input format is a space-separated list of strings, with the characters ' and " delimiting literal strings. Also, \ makes the next character be interpreted literally, but only outside a string. For example, here's an input file:

how\'dy 'hello world' aaa\

The items in this file are how'dy, hello world and aaa␤bbb (where is a newline character).

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.