Bash script error - Mandriva

This is a discussion on Bash script error - Mandriva ; This is from the Creatures Docking Station, which is really too old to use. But for my own knowledge, the bit below gives an error that 'dirname' is missing an operand; if [ "$fullpath" = "" ]; then fullpath="$1" fi ...

+ Reply to Thread
Results 1 to 17 of 17

Thread: Bash script error

  1. Bash script error

    This is from the Creatures Docking Station, which is really too old to use.

    But for my own knowledge, the bit below gives an error that 'dirname' is
    missing an operand;

    if [ "$fullpath" = "" ]; then
    fullpath="$1"
    fi
    # Is the awk/ls magic portable?
    if [ -L "$fullpath" ]; then
    fullpath="`ls -l "$fullpath" | awk '{print $11}'`"
    fi
    dirname $fullpath

    Setting a variable like this is common. Why doesn't it work in this
    instance? It should ultimately resolve to "dirname $1" or whatever
    fullpath is ultimately set at?

    TIA,

    Doug.

  2. Re: Bash script error

    On Tue, 08 Jan 2008 00:22:56 +1100, Doug Laidlaw wrote:
    >
    > But for my own knowledge, the bit below gives an error that 'dirname' is
    > missing an operand;


    Because it is. Trust the error message Luke.


    > Setting a variable like this is common.


    I hope not.

    > Why doesn't it work in this instance?


    Here try this.

    set -x # enable debugging mode

    if [ "$fullpath" = "" ]; then
    fullpath="$1"
    fi
    # Is the awk/ls magic portable?
    if [ -L "$fullpath" ]; then
    fullpath="`ls -l "$fullpath" | awk '{print $11}'`"
    fi

    dirname $fullpath

    set - # set debugging mode

  3. Re: Bash script error

    On Mon, 7 Jan 2008 16:23:40 +0000 (UTC), Bit Twister wrote:

    Opps,
    > set - # set debugging mode

    set - # set debugging mode off

  4. Re: Bash script error

    On Mon, 07 Jan 2008 11:54:12 -0500, Bit Twister wrote:

    > On Mon, 7 Jan 2008 16:23:40 +0000 (UTC), Bit Twister wrote:
    >
    > Opps,
    >> set - # set debugging mode

    > set - # set debugging mode off


    Lol. Care to try again ...

    set +x # set debugging mode off

    Since I'm correcting a type, there hasto be one somewhere in this msg too.

    Regards, Dave Hodgins

    --
    Change nomail.afraid.org to ody.ca to reply by email.
    (nomail.afraid.org has been set up specifically for
    use in usenet. Feel free to use it yourself.)

  5. Re: Bash script error

    On Mon, 07 Jan 2008 12:38:26 -0500, David W. Hodgins wrote:
    > On Mon, 07 Jan 2008 11:54:12 -0500,
    > Bit Twister wrote:


    >> set - # set debugging mode off

    >
    > Lol. Care to try again ...


    Nope. :-D

    > set +x # set debugging mode off


    Well, that does work. Just a habit for me to use "set -" since I might
    have used set -xv

    or any other switches.

  6. Re: Bash script error

    On Mon, 07 Jan 2008 12:47:24 -0500, Bit Twister wrote:

    > On Mon, 07 Jan 2008 12:38:26 -0500, David W. Hodgins wrote:
    >> On Mon, 07 Jan 2008 11:54:12 -0500,
    >> Bit Twister wrote:

    >
    >>> set - # set debugging mode off

    >> Lol. Care to try again ...

    >
    > Nope. :-D


    My bad. I should have checked the man page ...

    `-'
    Signal the end of options, cause all remaining ARGUMENTS to
    be assigned to the positional parameters. The `-x' and `-v'
    options are turned off. If there are no arguments, the
    positional parameters remain unchanged.

    I've always used set +x +v to turn off debugging. Didn't realize "set -",
    without the +x +v would turn them off.

    Learn something new everyday

    Regards, Dave Hodgins

    --
    Change nomail.afraid.org to ody.ca to reply by email.
    (nomail.afraid.org has been set up specifically for
    use in usenet. Feel free to use it yourself.)

  7. Re: Bash script error

    On Tue, 08 Jan 2008 00:22:56 +1100, Doug Laidlaw wrote:

    > if [ "$fullpath" = "" ]; then
    > fullpath="$1"
    > fi
    > # Is the awk/ls magic portable?
    > if [ -L "$fullpath" ]; then
    > fullpath="`ls -l "$fullpath" | awk '{print $11}'`"
    > fi
    > dirname $fullpath


    Was fullpath exported? Is this run in a shell?

    running fullpath=/etc/udev;export fullpath;foo.sh produces:

    /etc

    running fullpath="";export fullpath;foo.sh `pwd` produces:

    /home



  8. Re: Bash script error

    On Tue, 08 Jan 2008 00:22:56 +1100, Doug Laidlaw wrote:

    > This is from the Creatures Docking Station, which is really too old to
    > use.
    >
    > But for my own knowledge, the bit below gives an error that 'dirname' is
    > missing an operand;
    >
    > if [ "$fullpath" = "" ]; then
    > fullpath="$1"
    > fi
    > # Is the awk/ls magic portable?
    > if [ -L "$fullpath" ]; then
    > fullpath="`ls -l "$fullpath" | awk '{print $11}'`"
    > fi
    > dirname $fullpath
    >
    > Setting a variable like this is common. Why doesn't it work in this
    > instance? It should ultimately resolve to "dirname $1" or whatever
    > fullpath is ultimately set at?
    >
    > TIA,
    >
    > Doug.


    If the dirname is a link. Try changing 11 to 10 in the awk statement.

  9. Re: Bash script error

    On Mon, 07 Jan 2008 16:33:18 -0600, Jim Whitby wrote:

    > If the dirname is a link. Try changing 11 to 10 in the awk statement.


    and back to 11 if not.

  10. Re: Bash script error

    On Mon, 07 Jan 2008 22:53:24 +0000, Bit Twister wrote:

    > On Mon, 07 Jan 2008 16:33:18 -0600, Jim Whitby wrote:
    >
    >> If the dirname is a link. Try changing 11 to 10 in the awk statement.

    >
    > and back to 11 if not.


    If it isn't a link.... the test fails.... right?

  11. Re: Bash script error

    on Tuesday 08 January 2008 00:22
    in the Usenet newsgroup alt.os.linux.mandriva
    Doug Laidlaw wrote:

    > This is from the Creatures Docking Station, which is really too old to
    > use.
    >
    > But for my own knowledge, the bit below gives an error that 'dirname' is
    > missing an operand;
    >
    > if [ "$fullpath" = "" ]; then
    > fullpath="$1"
    > fi
    > # Is the awk/ls magic portable?
    > if [ -L "$fullpath" ]; then
    > fullpath="`ls -l "$fullpath" | awk '{print $11}'`"
    > fi
    > dirname $fullpath
    >
    > Setting a variable like this is common. Why doesn't it work in this
    > instance? It should ultimately resolve to "dirname $1" or whatever
    > fullpath is ultimately set at?
    >
    > TIA,
    >
    > Doug.


    Try running "bash -euxv