bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Problem with small script


From: Robert Parker
Subject: Re: Problem with small script
Date: Fri, 19 Feb 2016 00:22:20 +0700

On Thu, Feb 18, 2016 at 11:30 PM, Greg Wooledge <address@hidden> wrote:
On Thu, Feb 18, 2016 at 11:06:37PM +0700, Robert Parker wrote:
> The script:
> #/bin/bash
> # testlink.sh
> # must be run as root
>
> file1="$1"
> shift
> mandir=/usr/local/share/man/man3/
> cp "$file1" "$mandir"
> cd "$mandir"

You MUST check the result of cd.  If it fails but you continue on,
you will be operating in the wrong place.

Fair comment, but this has worked properly in an earlier version that did not rely on using shift.

> echo '$hash = '"$#"
> while (( "$#" )); do
>     file2="$1"
>     ln "$file1" "$file2"
>     shift
> done
>
> Results:
> >> sudo ./testlink.sh readfile.3 readtextfile.3
> $hash = 1
> ./testlink.sh: 11: ./testlink.sh: 1: not found
> >>

As near as I can tell, you are somehow running this script under sh
instead of bash.

address@hidden:~$ cat foo
#!/bin/bash
while (( "$#" )); do
  shift
done
address@hidden:~$ ./foo
address@hidden:~$ sh ./foo
./foo: 2: ./foo: 0: not found

Maybe you forgot to give it execute permissions, and therefore sudo
runs sh for you or something.  That's just a wild guess.  (Can't
reproduce that on my system.)  But whatever the reason, the behavior
you're seeing is fully consistent with executing it under the wrong
shell.
Not so:
chmod +x testlink.sh
always.

The wild card here is that I am running it under sudo because I am installing a man page in
 /usr/local/share/man/man3

and trying to link other names to said man page.

Is there any way I can tell which shell is running?
the top line in the script is
#/bin/bash

Is there any way I can tell which shell is in control?

Thanks for your response.

Bob



--
The Bundys, Cliven, Ted and Al. Great guys to look up to.

reply via email to

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