[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Syntax Question...
From: |
Greg Wooledge |
Subject: |
Re: Syntax Question... |
Date: |
Mon, 15 Aug 2011 08:31:24 -0400 |
User-agent: |
Mutt/1.4.2.3i |
On Mon, Aug 15, 2011 at 12:45:58AM -0700, Linda Walsh wrote:
> #!/bin/bash -exu
> alias sub=function
> alias unless='if !'
Aliases don't even *work* in scripts.
> typeset -xr sub unless
>
> declare -a SAVE_ARGS=( "$@" )
> typeset -xr snapdir='snapdir'
>
> # in shell: white is black and black is white:
> export b_false=1
> export b_true=0
> export Debug=$b_false Verbose=$b_true Silent=$b_false
> export Quiet=$b_false Force="" loglevel=7
Whatever your purpose is here, you're doing things in a very unclear
way.
verbose=0 # false
if ((verbose)); then
echo "blah blah blah"
fi
verbose=1 # true
if ((verbose)); then
echo "this one gets written"
fi
Also, don't export variables without a reason. Internal variables like
"b_false" do not need to appear in the environment of child processes.
> read progdir prog path export_blob <<<$(env_init "$progdir" "$prog" "$this")
If you are going to use <<< then you *must* quote the word which follows
it:
read a <<< "$b"
However, if your input source is a command rather than a variable
expansion, then you should probably be using < <() instead:
read progdir prog path export_blob < <(env_init "$progdir" "$prog" "$this")
> if [[ $#<1 ]]; then
> errx 50 "Need mount_path of fs to create snap_rdiff from"
> fi
I'd strongly suggest using ((...)) for arithmetic comparisons.
if (($#<1)); then
errx ...
fi
The [[ ... < ... ]] command does a *string* comparison. When comparing
to the string "1" it will usually work out as you expect, but consider
this:
a=42
if [[ $a < 7 ]]; then
echo "$a is less than 7?"
fi
I didn't read the rest.
As far as the original part of this thread is concerned: if you want a
reference to an array, use ksh93. Bash doesn't have them. In bash you
must use eval, with all its headaches, as shown in other messages of
this thread.
- Re: Syntax Question..., (continued)
- Re: Syntax Question..., Linda Walsh, 2011/08/14
- Re: Syntax Question..., Pierre Gaston, 2011/08/14
- Re: Syntax Question..., Linda Walsh, 2011/08/14
- Re: Syntax Question..., Pierre Gaston, 2011/08/14
- Re: Syntax Question..., Linda Walsh, 2011/08/14
- Re: Syntax Question..., Dennis Williamson, 2011/08/14
- Re: Syntax Question..., Linda Walsh, 2011/08/14
- Re: Syntax Question..., Dennis Williamson, 2011/08/15
- Re: Syntax Question..., Linda Walsh, 2011/08/15
- Re: Syntax Question..., Linda Walsh, 2011/08/15
- Re: Syntax Question...,
Greg Wooledge <=
- Re: Syntax Question..., Linda Walsh, 2011/08/18
- Re: Syntax Question..., Greg Wooledge, 2011/08/18
- Re: Syntax Question..., Chet Ramey, 2011/08/18
- Re: Syntax Question..., Greg Wooledge, 2011/08/18
- Re: Syntax Question..., Chet Ramey, 2011/08/18
- Re: Syntax Question..., Greg Wooledge, 2011/08/18
- Re: Syntax Question..., Chet Ramey, 2011/08/18
- Re: Syntax Question..., Linda Walsh, 2011/08/18
- Re: Syntax Question..., Ken Irving, 2011/08/18
- Re: Syntax Question..., Linda Walsh, 2011/08/18