Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #173382 > unrolled thread

My bash script is missing something - what?

Started byRichard Owlett <rowlett@cloud85.net>
First post2016-10-10 15:00 +0200
Last post2016-10-10 18:00 +0200
Articles 18 — 8 participants

Back to article view | Back to linux.debian.user


Contents

  My bash script is missing something - what? Richard Owlett <rowlett@cloud85.net> - 2016-10-10 15:00 +0200
    Re: My bash script is missing something - what? Robert Parker <rlp1938@gmail.com> - 2016-10-10 15:10 +0200
      Re: My bash script is missing something - what? Richard Owlett <rowlett@cloud85.net> - 2016-10-10 15:20 +0200
        Re: My bash script is missing something - what? Robert Parker <rlp1938@gmail.com> - 2016-10-10 15:30 +0200
        Re: My bash script is missing something - what? Greg Wooledge <wooledg@eeg.ccf.org> - 2016-10-10 15:30 +0200
          Re: My bash script is missing something - what? Greg Wooledge <wooledg@eeg.ccf.org> - 2016-10-10 16:20 +0200
          Re: My bash script is missing something - what? Nicolas George <george@nsup.org> - 2016-10-10 16:20 +0200
          PROGRESS - was [Re: My bash script is missing something - what?] Richard Owlett <rowlett@cloud85.net> - 2016-10-10 17:00 +0200
            Re: PROGRESS - was [Re: My bash script is missing something - what?] Nicolas George <george@nsup.org> - 2016-10-10 17:10 +0200
              Re: PROGRESS - was [Re: My bash script is missing something - what?] Richard Owlett <rowlett@cloud85.net> - 2016-10-10 17:50 +0200
                Re: PROGRESS - was [Re: My bash script is missing something - what?] Peter Hillier-Brook <phb@hbsys.plus.com> - 2016-10-10 18:30 +0200
                  Re: PROGRESS - was [Re: My bash script is missing something - what?] Greg Wooledge <wooledg@eeg.ccf.org> - 2016-10-10 18:40 +0200
            Re: PROGRESS - was [Re: My bash script is missing something - what?] Greg Wooledge <wooledg@eeg.ccf.org> - 2016-10-10 17:10 +0200
              Re: PROGRESS - was [Re: My bash script is missing something - what?] Richard Owlett <rowlett@cloud85.net> - 2016-10-10 17:50 +0200
        Re: My bash script is missing something - what? Lars Noodén <lars.nooden@gmail.com> - 2016-10-10 15:30 +0200
        Re: My bash script is missing something - what? "Thomas Schmitt" <scdbackup@gmx.net> - 2016-10-10 15:40 +0200
    Re: My bash script is missing something - what? Greg Wooledge <wooledg@eeg.ccf.org> - 2016-10-10 18:00 +0200
    Re: My bash script is missing something - what? songbird <songbird@anthive.com> - 2016-10-10 18:00 +0200

#173382 — My bash script is missing something - what?

FromRichard Owlett <rowlett@cloud85.net>
Date2016-10-10 15:00 +0200
SubjectMy bash script is missing something - what?
Message-ID<sqIlx-1ni-27@gated-at.bofh.it>
I have a trivial bash script named test.sh which has been marked 
as executable.
Its contents are:

#!/bin/bash
cat /etc/debian_version
mount | grep 'on / '

In a terminal I type:

test.sh

The response is:
bash: test.sh: command not found

I'm using Squeeze with Gnome2 as DE.
What's wrong?
TIA

[toc] | [next] | [standalone]


#173383

FromRobert Parker <rlp1938@gmail.com>
Date2016-10-10 15:10 +0200
Message-ID<sqIv8-1FC-37@gated-at.bofh.it>
In reply to#173382

[Multipart message — attachments visible in raw view] — view raw

you need to do:
./test.sh
instead.


On Mon, Oct 10, 2016 at 7:54 PM, Richard Owlett <rowlett@cloud85.net> wrote:

> I have a trivial bash script named test.sh which has been marked as
> executable.
> Its contents are:
>
> #!/bin/bash
> cat /etc/debian_version
> mount | grep 'on / '
>
> In a terminal I type:
>
> test.sh
>
> The response is:
> bash: test.sh: command not found
>
> I'm using Squeeze with Gnome2 as DE.
> What's wrong?
> TIA
>
>
>
>
>
>


-- 
Courtier "Sire I have bad news!"
King "Yes, what is it?"
Courtier "The peasants are revolting."
King "Yes they always have been. Now what is the bad news?"

[toc] | [prev] | [next] | [standalone]


#173384

FromRichard Owlett <rowlett@cloud85.net>
Date2016-10-10 15:20 +0200
Message-ID<sqIEO-1J7-13@gated-at.bofh.it>
In reply to#173383
On 10/10/2016 8:00 AM, Robert Parker wrote:
> you need to do:
> ./test.sh
> instead.
>

That just fails differently by responding:

: No such file or directory

I had seen that suggestion before while searching the web - don't 
recall a page reference. At the moment I using 
http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_01.html as 
my reference.


>
> On Mon, Oct 10, 2016 at 7:54 PM, Richard Owlett
> <rowlett@cloud85.net <mailto:rowlett@cloud85.net>> wrote:
>
>     I have a trivial bash script named test.sh which has been
>     marked as executable.
>     Its contents are:
>
>     #!/bin/bash
>     cat /etc/debian_version
>     mount | grep 'on / '
>
>     In a terminal I type:
>
>     test.sh
>
>     The response is:
>     bash: test.sh: command not found
>
>     I'm using Squeeze with Gnome2 as DE.
>     What's wrong?
>     TIA
>
>
>
>
>
>
>
>
> --
> Courtier "Sire I have bad news!"
> King "Yes, what is it?"
> Courtier "The peasants are revolting."
> King "Yes they always have been. Now what is the bad news?"

[toc] | [prev] | [next] | [standalone]


#173385

FromRobert Parker <rlp1938@gmail.com>
Date2016-10-10 15:30 +0200
Message-ID<sqIOt-1Mr-1@gated-at.bofh.it>
In reply to#173384

[Multipart message — attachments visible in raw view] — view raw

1. You have to be in the directory where the script resides.
2. Then:
chmod +x test.sh
3. Then:
./test.sh


On Mon, Oct 10, 2016 at 8:10 PM, Richard Owlett <rowlett@cloud85.net> wrote:

> On 10/10/2016 8:00 AM, Robert Parker wrote:
>
>> you need to do:
>> ./test.sh
>> instead.
>>
>>
> That just fails differently by responding:
>
> : No such file or directory
>
> I had seen that suggestion before while searching the web - don't recall a
> page reference. At the moment I using http://tldp.org/LDP/Bash-Begin
> ners-Guide/html/sect_02_01.html as my reference.
>
>
>
>> On Mon, Oct 10, 2016 at 7:54 PM, Richard Owlett
>> <rowlett@cloud85.net <mailto:rowlett@cloud85.net>> wrote:
>>
>>     I have a trivial bash script named test.sh which has been
>>     marked as executable.
>>     Its contents are:
>>
>>     #!/bin/bash
>>     cat /etc/debian_version
>>     mount | grep 'on / '
>>
>>     In a terminal I type:
>>
>>     test.sh
>>
>>     The response is:
>>     bash: test.sh: command not found
>>
>>     I'm using Squeeze with Gnome2 as DE.
>>     What's wrong?
>>     TIA
>>
>>
>>
>>
>>
>>
>>
>>
>> --
>> Courtier "Sire I have bad news!"
>> King "Yes, what is it?"
>> Courtier "The peasants are revolting."
>> King "Yes they always have been. Now what is the bad news?"
>>
>
>


-- 
Courtier "Sire I have bad news!"
King "Yes, what is it?"
Courtier "The peasants are revolting."
King "Yes they always have been. Now what is the bad news?"

[toc] | [prev] | [next] | [standalone]


#173386

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2016-10-10 15:30 +0200
Message-ID<sqIOu-1Mr-7@gated-at.bofh.it>
In reply to#173384
On Mon, Oct 10, 2016 at 08:10:33AM -0500, Richard Owlett wrote:
> On 10/10/2016 8:00 AM, Robert Parker wrote:
> >you need to do:
> >./test.sh
> >instead.
> >
> 
> That just fails differently by responding:
> 
> : No such file or directory

Carriage return.  Did you edit this script with a Microsoft Windows
program, perhaps?  The shebang line (#!/bin/bash) probably ends with
a carriage return + line feed, instead of just a line feed.

[toc] | [prev] | [next] | [standalone]


#173389

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2016-10-10 16:20 +0200
Message-ID<sqJAS-2hV-1@gated-at.bofh.it>
In reply to#173386
On Mon, Oct 10, 2016 at 04:10:22PM +0200, Nicolas George wrote:
> Le nonidi 19 vendémiaire, an CCXXV, Greg Wooledge a écrit :
> > > That just fails differently by responding:
> > > 
> > > : No such file or directory
> > 
> > Carriage return.  Did you edit this script with a Microsoft Windows
> > program, perhaps?  The shebang line (#!/bin/bash) probably ends with
> > a carriage return + line feed, instead of just a line feed.
> 
> I had the same diagnosis. Note that modern shells print a more useful
> diagnosis:
> 
> execve("/tmp/foo.sh", ["/tmp/foo.sh"], [/* 45 vars */]) = -1 ENOENT (No such file or directory)
> open("/tmp/foo.sh", O_RDONLY|O_NOCTTY)  = 3
> read(3, "#!/bin/sh\r\n", 64)            = 11
> close(3)                                = 0
> ioctl(2, TCGETS, {B38400 opost isig icanon echo ...}) = 0
> write(2, "zsh:1: /tmp/foo.sh: bad interpreter: /bin/sh^M: no such file or directory\n", 74) = 74
> exit_group(127)                         = ?

Actually, I'm going to change my diagnosis slightly.  The shebang is fine,
but the "cat /etc/debian_version" line has a carriage return at the end.
The error message is coming from cat.

If the shebang is wrong, bash (as interactive shell) prints:

bash: ./foo: /bin/bash^M: bad interpreter: No such file or directory

which is very close to your zsh message.  But putting the carriage return
on the cat command gives:

wooledg@wooledg:~$ ./foo
: No such file or directory

which is really:

wooledg@wooledg:~$ ./foo 2>&1 | less
cat: /etc/debian_version^M: No such file or directory

How the original poster ended up with a script with an extra carriage
return on just *one* line, rather than every line, is a mystery to me.

[toc] | [prev] | [next] | [standalone]


#173390

FromNicolas George <george@nsup.org>
Date2016-10-10 16:20 +0200
Message-ID<sqJAS-2hV-3@gated-at.bofh.it>
In reply to#173386

[Multipart message — attachments visible in raw view] — view raw

Le nonidi 19 vendémiaire, an CCXXV, Greg Wooledge a écrit :
> > That just fails differently by responding:
> > 
> > : No such file or directory
> 
> Carriage return.  Did you edit this script with a Microsoft Windows
> program, perhaps?  The shebang line (#!/bin/bash) probably ends with
> a carriage return + line feed, instead of just a line feed.

I had the same diagnosis. Note that modern shells print a more useful
diagnosis:

execve("/tmp/foo.sh", ["/tmp/foo.sh"], [/* 45 vars */]) = -1 ENOENT (No such file or directory)
open("/tmp/foo.sh", O_RDONLY|O_NOCTTY)  = 3
read(3, "#!/bin/sh\r\n", 64)            = 11
close(3)                                = 0
ioctl(2, TCGETS, {B38400 opost isig icanon echo ...}) = 0
write(2, "zsh:1: /tmp/foo.sh: bad interpreter: /bin/sh^M: no such file or directory\n", 74) = 74
exit_group(127)                         = ?

-- 
  Nicolas George

[toc] | [prev] | [next] | [standalone]


#173394 — PROGRESS - was [Re: My bash script is missing something - what?]

FromRichard Owlett <rowlett@cloud85.net>
Date2016-10-10 17:00 +0200
SubjectPROGRESS - was [Re: My bash script is missing something - what?]
Message-ID<sqKdz-2uP-3@gated-at.bofh.it>
In reply to#173386
On 10/10/2016 8:21 AM, Greg Wooledge wrote:
> On Mon, Oct 10, 2016 at 08:10:33AM -0500, Richard Owlett wrote:
>> On 10/10/2016 8:00 AM, Robert Parker wrote:
>>> you need to do:
>>> ./test.sh
>>> instead.
>>>
>>
>> That just fails differently by responding:
>>
>> : No such file or directory
>
> Carriage return.  Did you edit this script with a Microsoft Windows
> program, perhaps?  The shebang line (#!/bin/bash) probably ends with
> a carriage return + line feed, instead of just a line feed.

You were on the right track.
My editor was gedit under Squeeze.
*HOWEVER*, as my original was saved to a flash drive that I also 
use to transfer information to/from my Windows machines, I had 
saved with Windows' line endings ;/

It now, like the proverbial child, it does what I _told_ it to do 
but not quite what I _wanted_ it to do.

1. What Debian oriented Bash Tutorial should I be reading?
2. What is a clean/neat/??? way to double-click on the file name 
and have it:
      open a terminal window [currently it prompts rather than do]
      run the script
      have window remain open until explicitly dismissed
       [I approximate the last with a "read trashvariable" as 
last line.]
3. As written each line appears in the window followed by 
response on the next line.
   Inelegant ;<

Thanks for all the responses.

[toc] | [prev] | [next] | [standalone]


#173396 — Re: PROGRESS - was [Re: My bash script is missing something - what?]

FromNicolas George <george@nsup.org>
Date2016-10-10 17:10 +0200
SubjectRe: PROGRESS - was [Re: My bash script is missing something - what?]
Message-ID<sqKnf-2Nn-11@gated-at.bofh.it>
In reply to#173394

[Multipart message — attachments visible in raw view] — view raw

Le nonidi 19 vendémiaire, an CCXXV, Richard Owlett a écrit :
> 1. What Debian oriented Bash Tutorial should I be reading?

My first tutorial advice: do not do bash. I advise to do either or both of:
learn standard sh for portable scripts and for more advanced scripting learn
a modern shell less encumbered by backward compatibility with Bourne shell
misfeatures than bash.

Regards,

-- 
  Nicolas George

[toc] | [prev] | [next] | [standalone]


#173400 — Re: PROGRESS - was [Re: My bash script is missing something - what?]

FromRichard Owlett <rowlett@cloud85.net>
Date2016-10-10 17:50 +0200
SubjectRe: PROGRESS - was [Re: My bash script is missing something - what?]
Message-ID<sqKZY-2ZY-17@gated-at.bofh.it>
In reply to#173396
On 10/10/2016 10:04 AM, Nicolas George wrote:
> Le nonidi 19 vendémiaire, an CCXXV, Richard Owlett a écrit :
>> 1. What Debian oriented Bash Tutorial should I be reading?
>
> My first tutorial advice: do not do bash. I advise to do either or both of:
> learn standard sh for portable scripts and for more advanced scripting learn
> a modern shell less encumbered by backward compatibility with Bourne shell
> misfeatures than bash.
>

As my first programming course preceded Mr. Torvalds' birth, old 
tools and I share some underlying assumptions. Besides one of my 
projects requires dash ;/

[toc] | [prev] | [next] | [standalone]


#173404 — Re: PROGRESS - was [Re: My bash script is missing something - what?]

FromPeter Hillier-Brook <phb@hbsys.plus.com>
Date2016-10-10 18:30 +0200
SubjectRe: PROGRESS - was [Re: My bash script is missing something - what?]
Message-ID<sqLCG-3rZ-29@gated-at.bofh.it>
In reply to#173400
On 10/10/16 16:46, Richard Owlett wrote:
> On 10/10/2016 10:04 AM, Nicolas George wrote:
>> Le nonidi 19 vendémiaire, an CCXXV, Richard Owlett a écrit :
>>> 1. What Debian oriented Bash Tutorial should I be reading?
>>
>> My first tutorial advice: do not do bash. I advise to do either or
>> both of:
>> learn standard sh for portable scripts and for more advanced scripting
>> learn
>> a modern shell less encumbered by backward compatibility with Bourne
>> shell
>> misfeatures than bash.
>>
> 
> As my first programming course preceded Mr. Torvalds' birth, old tools
> and I share some underlying assumptions. Besides one of my projects
> requires dash ;/

Ignoring your youth, you need to precede your script with a valid path
such as './' :-)

[toc] | [prev] | [next] | [standalone]


#173405 — Re: PROGRESS - was [Re: My bash script is missing something - what?]

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2016-10-10 18:40 +0200
SubjectRe: PROGRESS - was [Re: My bash script is missing something - what?]
Message-ID<sqLMm-3uW-13@gated-at.bofh.it>
In reply to#173404
On Mon, Oct 10, 2016 at 05:19:34PM +0100, Peter Hillier-Brook wrote:
> Ignoring your youth, you need to precede your script with a valid path
> such as './' :-)

He did.

[toc] | [prev] | [next] | [standalone]


#173398 — Re: PROGRESS - was [Re: My bash script is missing something - what?]

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2016-10-10 17:10 +0200
SubjectRe: PROGRESS - was [Re: My bash script is missing something - what?]
Message-ID<sqKnf-2Nn-23@gated-at.bofh.it>
In reply to#173394
On Mon, Oct 10, 2016 at 09:58:44AM -0500, Richard Owlett wrote:
> 1. What Debian oriented Bash Tutorial should I be reading?

http://mywiki.wooledge.org/BashGuide is decent.  However, I might be
slightly biased.

[toc] | [prev] | [next] | [standalone]


#173401 — Re: PROGRESS - was [Re: My bash script is missing something - what?]

FromRichard Owlett <rowlett@cloud85.net>
Date2016-10-10 17:50 +0200
SubjectRe: PROGRESS - was [Re: My bash script is missing something - what?]
Message-ID<sqKZY-2ZY-19@gated-at.bofh.it>
In reply to#173398
On 10/10/2016 10:01 AM, Greg Wooledge wrote:
> On Mon, Oct 10, 2016 at 09:58:44AM -0500, Richard Owlett wrote:
>> 1. What Debian oriented Bash Tutorial should I be reading?
>
> http://mywiki.wooledge.org/BashGuide is decent.

Now bookmarked. Neglected to do so last time I was looking.

>  However, I might be slightly biased.

Lack of bias can be overrated ;/
P.S. FAQ65 points in useful direction for one of my sub-questions.

[toc] | [prev] | [next] | [standalone]


#173387

FromLars Noodén <lars.nooden@gmail.com>
Date2016-10-10 15:30 +0200
Message-ID<sqIOu-1Mr-13@gated-at.bofh.it>
In reply to#173384
On 10/10/2016 04:10 PM, Richard Owlett wrote:
> On 10/10/2016 8:00 AM, Robert Parker wrote:
>> you need to do:
>> ./test.sh
>> instead.
>>
> 
> That just fails differently by responding:
> 
> : No such file or directory

Where ever the script is, it does have to be in the $PATH or else you
must run it using including a relative or absolute path to its location.

About your error message "bash: test.sh: command not found", you might
try putting the full paths to mount and grep in your script.  Or else
explicitly set the $PATH variable to something useful at the beginning
of the script.

If that was not it, you can use the set -x option with bash to trace the
script's actions.

	#!/bin/bash -x

That prints out each line as it will be run just before it is actually
run, to see what precisely is causing the failure.

Regards,
Lars

[toc] | [prev] | [next] | [standalone]


#173388

From"Thomas Schmitt" <scdbackup@gmx.net>
Date2016-10-10 15:40 +0200
Message-ID<sqIYa-1PF-31@gated-at.bofh.it>
In reply to#173384
Hi,

Richard Owlett wrote:
> > >      bash: test.sh: command not found

Robert Parker wrote:
> > you need to do:./test.sh

Richard Owlett wrote:
> That just fails differently by responding:
> : No such file or directory
> At the moment I using
>   http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_02_01.html

It states
  "If you did not put the scripts directory in your PATH, and . (the
   current directory) is not in the PATH either, you can activate the
   script like this:

     ./script_name.sh 
  "

So on the first hand it was about the environment variable named "PATH".
Do

  echo $PATH

to get a list of directories where programs will be found automatically.
The directory paths are separated by ':' characters. E.g.

  /usr/local/bin:/usr/bin:/usr/local/games:/usr/games:/home/thomas/bin

----------------------------------------------------------------------

But what does now prevent proper execution ?

I tested the script as shown by you. It works and says

  8.X
  /dev/sdaY on / type ext4 (rw,noatime,discard,errors=remount-ro,data=ordered)

(with X and Y being private numbers. :))

So this must be some flaw hidden from the human eye and copy+paste.

Be so kind and let program "od" show the bytes of your script.

  od -c test.sh

For me it says

  0000000   #   !   /   b   i   n   /   b   a   s   h  \n   c   a   t    
  0000020   /   e   t   c   /   d   e   b   i   a   n   _   v   e   r   s
  0000040   i   o   n  \n   m   o   u   n   t       |       g   r   e   p
  0000060       '   o   n       /       '  \n  \n
  0000072

This should show us any CarriageReturn characters, which Greg suspects
to be to blame.


Lars Norden wrote:
>         #!/bin/bash -x

Good proposal, too.
(I would have proposed command

   set -x

as second line of the script.)


Have a nice day :)

Thomas

[toc] | [prev] | [next] | [standalone]


#173402

FromGreg Wooledge <wooledg@eeg.ccf.org>
Date2016-10-10 18:00 +0200
Message-ID<sqL9D-33e-3@gated-at.bofh.it>
In reply to#173382
On Mon, Oct 10, 2016 at 11:51:37AM -0400, songbird wrote:
> Richard Owlett wrote:
> > I have a trivial bash script named test.sh which has been marked 
> > as executable.

>   also remember that test itself is a builtin
> or binary on some systems.

It's required by POSIX, so it will be a command on *every* system.
Whether it's a shell builtin is not specified, but every modern shell
makes it a builtin -- even dash.

>   you may be running on thing and thinking
> you are running another.
> 
>   in this particular case with the .sh 
> extension you are safe, but forget that
> once and ...

Yes, this is excellent advice.  After being bitten by this once or twice
in my early Unix years, I stopped making commands called "test" and made
commands called "foo", "bar", "foobar", etc.

[toc] | [prev] | [next] | [standalone]


#173403

Fromsongbird <songbird@anthive.com>
Date2016-10-10 18:00 +0200
Message-ID<sqL9D-33e-5@gated-at.bofh.it>
In reply to#173382
Richard Owlett wrote:
> I have a trivial bash script named test.sh which has been marked 
> as executable.
> Its contents are:
>
> #!/bin/bash
> cat /etc/debian_version
> mount | grep 'on / '
>
> In a terminal I type:
>
> test.sh
>
> The response is:
> bash: test.sh: command not found
>
> I'm using Squeeze with Gnome2 as DE.
> What's wrong?
> TIA

  also remember that test itself is a builtin
or binary on some systems.

  you may be running on thing and thinking
you are running another.

  in this particular case with the .sh 
extension you are safe, but forget that
once and ...


  songbird

[toc] | [prev] | [standalone]


Back to top | Article view | linux.debian.user


csiph-web