[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: impressions of a new user
- To: tech_(_at_)_openbsd_(_dot_)_org
- Subject: Re: impressions of a new user
- From: Marc Bevand <bevand_m_(_at_)_epita_(_dot_)_fr>
- Date: Fri, 15 Aug 2003 21:42:10 +0200
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.
Visit your host, monkey.org