[Top][All Lists]

[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/

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

verbose=0  # false
if ((verbose)); then
  echo "blah blah blah"

verbose=1  # true
if ((verbose)); then
  echo "this one gets written"

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

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 ...

The [[ ... < ... ]] command does a *string* comparison.  When comparing
to the string "1" it will usually work out as you expect, but consider

if [[ $a < 7 ]]; then
  echo "$a is less than 7?"

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.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]