Re: My bash script is missing something - what?

2016-10-10 Thread Tony Baldwin




 Forwarded Message 
Subject: Re: My bash script is missing something - what?
To: Richard Owlett <rowl...@cloud85.net>
References: <57fb8f79.9010...@cloud85.net>
From: Anthony Baldwin <baldwinling...@gmx.com>
Message-ID: <3e26c189-eab5-d400-c3c7-5cc1d7321...@gmx.com>
Date: Mon, 10 Oct 2016 13:06:59 -0400
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 
Icedove/45.2.0

MIME-Version: 1.0
In-Reply-To: <57fb8f79.9010...@cloud85.net>
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Transfer-Encoding: 7bit



On 10/10/2016 08:54 AM, 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



Is it in your $PATH? (i.e in ~/bin, if that is added to your path, or in 
/usr/local/bin, or /usr/bin, etc. I put all my bash (or tcl or python or 
ruby or perl)scripts  in /home/me/bin, which I have added to my $PATH
If the script is not in your path, you will have to cd to the directory 
it is in and do

$ ./test.sh
with that ./

I think you got that answer already,
but, as a side note (just a thought):
you could make this a one-liner, and even make an alias for it in your 
.bashrc,

like
# frp for find root partition
alias  frp = cat /etc/debian_version && mount | grep 'on / '
Then you could simply type frp and get the info you want.
close your terminal and start a new one to use the alias once it's added 
to the .bashrc file, of course)








--
http://www.baldwinlinguas.com
translations, localization,
multilingual web development
EN, ES, FR, PT



Re: My bash script is missing something - what?

2016-10-10 Thread gricketson
On 2016-10-10 10:57, Greg Wooledge wrote:
> 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.
This is a very good point, and one example on Debian Wheezy:
Look at /usr/bin/test
and see 
'man test'
or 
'info coreutils 'test invocation''
---
http://elchanate.org/



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

2016-10-10 Thread Greg Wooledge
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.



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

2016-10-10 Thread Peter Hillier-Brook
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 './' :-)



Re: My bash script is missing something - what?

2016-10-10 Thread Greg Wooledge
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.



Re: My bash script is missing something - what?

2016-10-10 Thread songbird
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



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

2016-10-10 Thread Richard Owlett

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






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

2016-10-10 Thread Richard Owlett

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.



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

2016-10-10 Thread Nicolas George
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


signature.asc
Description: Digital signature


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

2016-10-10 Thread Greg Wooledge
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.



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

2016-10-10 Thread Richard Owlett

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.





Re: My bash script is missing something - what?

2016-10-10 Thread Greg Wooledge
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.



Re: My bash script is missing something - what?

2016-10-10 Thread Nicolas George
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


signature.asc
Description: Digital signature


Re: My bash script is missing something - what?

2016-10-10 Thread Thomas Schmitt
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

  000   #   !   /   b   i   n   /   b   a   s   h  \n   c   a   t
  020   /   e   t   c   /   d   e   b   i   a   n   _   v   e   r   s
  040   i   o   n  \n   m   o   u   n   t   |   g   r   e   p
  060   '   o   n   /   '  \n  \n
  072

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



Re: My bash script is missing something - what?

2016-10-10 Thread Greg Wooledge
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.



Re: My bash script is missing something - what?

2016-10-10 Thread Robert Parker
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  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
>> > 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?"


Re: My bash script is missing something - what?

2016-10-10 Thread Lars Noodén
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



Re: My bash script is missing something - what?

2016-10-10 Thread Richard Owlett

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
> 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?"




Re: My bash script is missing something - what?

2016-10-10 Thread Robert Parker
you need to do:
./test.sh
instead.


On Mon, Oct 10, 2016 at 7:54 PM, 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
>
>
>
>
>
>


-- 
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?"


My bash script is missing something - what?

2016-10-10 Thread Richard Owlett
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