Bash calls TCL, TCL calls Bash, 2nd Bash never reads input

Bash calls TCL, TCL calls Bash, 2nd Bash never reads input

Post by those who know me have no need of my nam » Sun, 04 Jan 2004 11:33:02



[fu-t set]

in comp.unix.misc i read:

Quote:>I'm sorry but it's the ONLY way I can write this.  I don't know how to
>read standard in in TCL; I don't know how to do complex string
>manipulation in Bash.  So I have to write in the languages based on
>what I know.

perhaps you should resolve these deficiencies -- not that there is anything
wrong with using tcl from bash or bash from tcl, but it doesn't appear
necessary in this case.

in terms of shell scripting you don't have much debugging experience, in
particular you don't appear to have used ``set -vx'' to expose the
operations occurring.  which would lead to the real problem: you aren't
using enough quoting, which is causing ...

Quote:>Problem arises in fileremoval.sh - it just plain does not work, here
>is the error:

>/home/phillip/scripts/fileremoval.sh: [: ==: unary operator expected

you have a test which expects certain arguments and they are not being
provided.  you use bare variable expansion, which does not result in an
argument being created if the variable is unset or empty.  let's look at
what that looks like using set -x.

my little test script, which is whittled down to just the problem, is:

  #!/usr/bin/bash
  set -x
  foo=''
  [ $foo == 'Y' ]

executing this provides the following output:

  + foo=
  + '[' == Y ']'
  ./foo.sh: line 4: [: ==: unary operator expected

as you can see there is no argument before the == (which is non-standard
btw), because foo is empty.  to ensure that an argument is created you need
to use quotes, i.e.,

  #!/usr/bin/bash
  set -x
  foo=''
  [ "$foo" == 'Y' ]

which after expansion becomes:

  + foo=
  + '[' '' == Y ']'

there we see that there is an empty argument being provided.

--
a signature

 
 
 

Bash calls TCL, TCL calls Bash, 2nd Bash never reads input

Post by Phil Powe » Mon, 05 Jan 2004 04:07:30



Quote:> [fu-t set]

> in comp.unix.misc i read:

> >I'm sorry but it's the ONLY way I can write this.  I don't know how to
> >read standard in in TCL; I don't know how to do complex string
> >manipulation in Bash.  So I have to write in the languages based on
> >what I know.

> perhaps you should resolve these deficiencies -- not that there is anything
> wrong with using tcl from bash or bash from tcl, but it doesn't appear
> necessary in this case.

> in terms of shell scripting you don't have much debugging experience, in
> particular you don't appear to have used ``set -vx'' to expose the
> operations occurring.  which would lead to the real problem: you aren't
> using enough quoting, which is causing ...

Sorry, my tutorial never taught me set -vx so I never knew about it,
but now I do and it will come in handy, thanx.

- Show quoted text -

Quote:

> >Problem arises in fileremoval.sh - it just plain does not work, here
> >is the error:

> >/home/phillip/scripts/fileremoval.sh: [: ==: unary operator expected

> you have a test which expects certain arguments and they are not being
> provided.  you use bare variable expansion, which does not result in an
> argument being created if the variable is unset or empty.  let's look at
> what that looks like using set -x.

> my little test script, which is whittled down to just the problem, is:

>   #!/usr/bin/bash
>   set -x
>   foo=''
>   [ $foo == 'Y' ]

> executing this provides the following output:

>   + foo=
>   + '[' == Y ']'
>   ./foo.sh: line 4: [: ==: unary operator expected

> as you can see there is no argument before the == (which is non-standard
> btw), because foo is empty.  to ensure that an argument is created you need
> to use quotes, i.e.,

>   #!/usr/bin/bash
>   set -x
>   foo=''
>   [ "$foo" == 'Y' ]

> which after expansion becomes:

>   + foo=
>   + '[' '' == Y ']'

> there we see that there is an empty argument being provided.

Ok, BTW I use "==" because it works, whether it's non-standard or not
is irrelevant when I get all kinds of errors with -eq for strings.  So
I gave up and used ==.  But that's good to know that it must be
instantiated and non-null.  Usually I would do this:

if [ $foo ] && [ $foo == 'Y' ]; then; #blah; fi

But that is my C-derivative background coming into play.  In most
C-derivative languages nullness is handled a lot more friendly than
shell or bash script.  Ok , is it "shell script" or "bash script"?
Which is the correct term to use?

Thanx again
Phil

 
 
 

Bash calls TCL, TCL calls Bash, 2nd Bash never reads input

Post by those who know me have no need of my nam » Mon, 05 Jan 2004 13:04:31


[groups trimmed]

in comp.unix.shell i read:

Quote:>BTW I use "==" because it works, whether it's non-standard or not
>is irrelevant when I get all kinds of errors with -eq for strings.  

it appears that you need to read a bit more too.  -eq is for numeric
comparisons.  the standard symbol for string comparison is =.

Quote:>Ok , is it "shell script" or "bash script"?
>Which is the correct term to use?

shell script is a generic term.  one might use it if you didn't want to
denote the particular interpreter.  in some cases it's used to mean the
script is generic enough to work with any interpreter of a general class,
usually either bourne or csh.  a bash script would mean that the script
specifically uses features of bash, and would likely fail if used with any
other interpreter (or that one was ignorant of other shells).

--
a signature

 
 
 

Bash calls TCL, TCL calls Bash, 2nd Bash never reads input

Post by lvir.. » Wed, 07 Jan 2004 22:41:38



:  Ok , is it "shell script" or "bash script"?
:Which is the correct term to use?

If the script uses bash specific features, it probably is more correct
to say "bash script".  Otherwise, most just say "shell script".

--
<URL: http://wiki.tcl.tk/ > In God we trust.
Even if explicitly stated to the contrary, nothing in this posting
should be construed as representing my employer's opinions.