bash, word splitting, and command substitution
From: Joe Pfeiffer (pfeiffer_at_cs.nmsu.edu)
Date: 12/21/04
- Next message: CV: "Re: Mozilla will not display top level dir of ntfs partition (Mandrake10.1)"
- Previous message: Måns Rullgård: "Re: Mozilla will not display top level dir of ntfs partition (Mandrake10.1)"
- Next in thread: Robert Nichols: "Re: bash, word splitting, and command substitution"
- Reply: Robert Nichols: "Re: bash, word splitting, and command substitution"
- Reply: Joe Pfeiffer: "Re: bash, word splitting, and command substitution"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 21 Dec 2004 15:00:18 -0700
I would like to use the contents of a file as the command line
arguments to a program, within a bash script. I need word splitting
to occur in the contents I'm pulling from the file, and I'm not
getting the results I expect. I'm using double quote characters in
the file to try to control the word splitting
If the command appears in the script as
command $(< file)
every word in the file is split -- that is, the quotes in the file are
just treated as ordinary characters, so every word is a separate
argument.
If I try any variation that I've been able to think of for quoting the
command substition like this
command "$(< file)"
the whole file contents appear as a single argument. I've tried both
single and double quotes.
I've tried every variation on quoting within the file that I can think
of, including single quotes, double quotes, and inhibiting
interpretation of spaces with back-slashes.
It doesn't matter whether I use the form of command substition shown,
actually use a cat command, or use back quotes and the cat command.
Below is a specific script and test data that show the problem.
Instead of the expected (well, I expected it!) behavior showing a
dialog box with two lines of choices, I'm seeing something more like
1 "...
Preshow ..."
\ 2
" 1
Rousing Overture
and Footsteps"
----------------shell script---------------------------
#!/bin/sh
dialog --nocancel --title "Testing..." --menu "Just a Test..." 20 60 10 $(< menulist)
----------------contents of file 'menulist'------------
1 "... Preshow ..." \
2 " 1 Rousing Overture and Footsteps" \
- Next message: CV: "Re: Mozilla will not display top level dir of ntfs partition (Mandrake10.1)"
- Previous message: Måns Rullgård: "Re: Mozilla will not display top level dir of ntfs partition (Mandrake10.1)"
- Next in thread: Robert Nichols: "Re: bash, word splitting, and command substitution"
- Reply: Robert Nichols: "Re: bash, word splitting, and command substitution"
- Reply: Joe Pfeiffer: "Re: bash, word splitting, and command substitution"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|