Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.os.linux.misc > #35740
| From | Ralf Fassel <ralfixx@gmx.de> |
|---|---|
| Newsgroups | comp.os.linux.misc |
| Subject | Re: correct quoting for variables in bash scripts? |
| Date | 2022-10-18 11:31 +0200 |
| Message-ID | <ygailkh8om8.fsf@akutech.de> (permalink) |
| References | <tije9a$19dt$1@gioia.aioe.org> <eli$2210171923@qaz.wtf> |
* Eli the Bearded <*@eli.users.panix.com>
| In your example neither is needed. Firstly there's nothing adjoining to
| confuse the variable name. Secondly, it is [[ not [.
>
| The one [ ] square bracket form of the test command needs empty string
| protection because variable expansion happens before thecommand is run.
>
| The two [[ ]] square bracket form of the test command is explicitly a
| shell built-in, so it can recognize empty strings without help.
Interesting, didn't know that difference:
$ unset bar
$ [[ $bar = x ]] && echo yes
$ type [[
[[ is a shell keyword
$ [ $bar = x ] && echo yes
bash: [: =: unary operator expected
$ type [
[ is a shell builtin
Most probably the error thrown with "[" is to ensure compatibility with
/usr/bin/test?
R'
Back to comp.os.linux.misc | Previous | Next — Previous in thread | Next in thread | Find similar
correct quoting for variables in bash scripts? Barry Stir <scooter@mealteam6.mil> - 2022-10-17 19:28 +0800
Re: correct quoting for variables in bash scripts? Aragorn <telcontar@duck.com> - 2022-10-17 14:10 +0200
Re: correct quoting for variables in bash scripts? Ralf Fassel <ralfixx@gmx.de> - 2022-10-17 14:15 +0200
Re: correct quoting for variables in bash scripts? Jerry Peters <jerry@example.invalid> - 2022-11-01 20:27 +0000
Re: correct quoting for variables in bash scripts? "Carlos E. R." <robin_listas@es.invalid> - 2022-10-17 14:39 +0200
Re: correct quoting for variables in bash scripts? Rich <rich@example.invalid> - 2022-10-17 14:02 +0000
Re: correct quoting for variables in bash scripts? Henning Hucke <h_hucke+spam.news@newsmail.aeon.icebear.org> - 2022-10-17 13:54 +0000
Re: correct quoting for variables in bash scripts? Eli the Bearded <*@eli.users.panix.com> - 2022-10-17 23:35 +0000
Re: correct quoting for variables in bash scripts? Ralf Fassel <ralfixx@gmx.de> - 2022-10-18 11:31 +0200
Re: correct quoting for variables in bash scripts? Rich <rich@example.invalid> - 2022-10-18 12:02 +0000
Re: correct quoting for variables in bash scripts? Ralf Fassel <ralfixx@gmx.de> - 2022-10-18 15:01 +0200
Re: correct quoting for variables in bash scripts? Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2022-10-18 14:17 +0000
The difference between /bin/test and /bin/[ Lew Pitcher <lew.pitcher@digitalfreehold.ca> - 2022-10-18 14:58 +0000
Re: The difference between /bin/test and /bin/[ Eli the Bearded <*@eli.users.panix.com> - 2022-10-21 04:41 +0000
Re: correct quoting for variables in bash scripts? Ralf Fassel <ralfixx@gmx.de> - 2022-10-19 12:04 +0200
csiph-web