[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: impressions of a new user



On 15 Aug 2003, Zvezdan Petkovic wrote:
| 
| I really like OpenBSDs choice of ksh as a default sh shell.  It's small
| compared to bash, and, frankly, I still have scripts that fail under
| bash on RH9 and work with no trouble in ksh.  Here's a contrived example
| made from a much more complex script stripping it to a bare minimum, and
| changing "awk" line to a simple "cat" and "rsync" line to "ls".
| I also simplified a list to demonstrate the issue.
| 
| A file list.txt contains
| ====== cut =======
| .X{modmap,defaults}
| ====== cut =======
| 
| A file buginbash.sh contains:
| ====== cut =======
| #!/bin/bash
| CMD="cat list.txt"
| ls $(${CMD})
| ====== cut =======
| 
| When run in my home directory it gives:
| $ ./buginbash.sh 
| ls: .X{modmap,defaults}: No such file or directory
| 
| When "#!/bin/bash" is changed to "#!/bin/ksh" and run again the result
| is:
| 
| $ ./buginbash.sh
| .Xdefaults  .Xmodmap
| 
| as it should be.

No, it's wrong. You are using brace expansion, this is not a POSIX
feature, so different shells may implement it differently.

Bash has choosed to do it before command substitution, see bash(1):

	Brace expansion is performed before any other expansions [...]

Ksh has choosed to do it after, see ksh(1):

	The results of substitution [parameter, command, and
	arithmetic substitutions] are, unless otherwise specified,
	also subject to brace expansion [...]

-- 
Marc Bevand                          http://www.epita.fr/~bevand_m
Computer Science School EPITA - System, Network and Security Dept.