Re: Bash question hard to formulate

2020-08-03 Thread David Wright
On Mon 03 Aug 2020 at 11:30:42 (+0200), Esteban L wrote:

> I am not typing return. I am typing in a sentence...As I receive new
> output to the terminal window, and I continue typing, my text stream
> just goes down a line. Which is fine, UNLESS I otherwise want to correct
> something, and backspacing doesn't word wrap back to the previously
> typed line.

If characters are typed by a process while you're typing a command
line, then naively trying to backspace over a newline will not work
because bash has a different idea of where the cursor is from reality.

If you just ignore said characters, the command line you typed will
be unaffected, and will execute correctly when you press Return.

> the main thing I want is, if I backspace into a sentence (as I am
> receiving output to the terminal window and that i have not CR'ed), that
> the incomplete sentence will re-show up on the active line, when I reach
> the beginning of the that line.

That's not going to work. When you "backspace into a sentence", you're
rubbing out characters that *you* typed, even though the characters
that are actually disappearing from the display are the ones that were
displayed last, ie those output by the other process.

If you want the characters that *you* typed to be re-shown, clean, on
the command line, then pressing Ctrl-L is the correct way to do it.
*Then* apply your corrections, using Backspace or the arrow keys as
appropriate.

Cheers,
David.



Re: Bash question hard to formulate

2020-08-03 Thread songbird
 wrote:
> On Mon, Aug 03, 2020 at 12:47:32AM -0400, songbird wrote:
>> ...
>>=20
>>   i'm not familiar with that problem but another tip
>> which is helpful when dealing with a terminal that
>> gets into a strange state is to press return then
>> type in reset and press return again.
>
> Typing return when you have already half-a-command line
> (and are not sure what it is) is somewhat dangerous.
>
> That's OK, it can be a life style. Be sure to keep some
> backups around, then :-)

  haha, yeah...  with github these days my more recent
projects are being backed up "off site" so i'm not too
worried about the most recent changes not being 
available to me in case of a severe crash.  but i do
also keep backups.

  Ctrl-C can also be used to cancel a command in progress.
:)  i'm not often typing dangerous commands into the 
terminal, especially one which is in an odd state.


  songbird



Re: Bash question hard to formulate

2020-08-03 Thread Esteban L
I think that is the main thing.

I am not typing return. I am typing in a sentence...As I receive new
output to the terminal window, and I continue typing, my text stream
just goes down a line. Which is fine, UNLESS I otherwise want to correct
something, and backspacing doesn't word wrap back to the previously
typed line.

Had trouble sleeping =) trying to figure it out.

I don't know if it's Bash related, inputrc, terminal, debian, or whatever.

I was reading that perhaps setting the "auto left margin" to ON, would
allow the cursor to wordwrap (in reverse) to the previous line.

I have thought about using a different terminal window, but so far they
all seem to exhibit the same behavior. I thought gnome-terminal was
bloated, and had extra features compared to other sleeker versions - but
alas, it also exhibits this behavior.

Though, I admit, i am almost at my wits end.

I assume everyone has this behavior from Debian? I only have default
settings, on two boxes (Debian 9, and Debian 10), and the behavior is
the same on both. EPP! I just realized, I have 4 Debians =D The behavior
is the same on all of them.

the main thing I want is, if I backspace into a sentence (as I am
receiving output to the terminal window and that i have not CR'ed), that
the incomplete sentence will re-show up on the active line, when I reach
the beginning of the that line.

I think this is one of those classic examples of "it's easy if you know
how" =) But, if you don't, it's as hard as humanly possible.


On 8/3/20 10:12 AM, to...@tuxteam.de wrote:
> On Mon, Aug 03, 2020 at 12:47:32AM -0400, songbird wrote:
>> ...
>>
>>   i'm not familiar with that problem but another tip
>> which is helpful when dealing with a terminal that
>> gets into a strange state is to press return then
>> type in reset and press return again.
> Typing return when you have already half-a-command line
> (and are not sure what it is) is somewhat dangerous.
>
> That's OK, it can be a life style. Be sure to keep some
> backups around, then :-)
>
> Cheers
> -- t



signature.asc
Description: OpenPGP digital signature


Re: Bash question hard to formulate

2020-08-03 Thread tomas
On Mon, Aug 03, 2020 at 12:47:32AM -0400, songbird wrote:
> ...
> 
>   i'm not familiar with that problem but another tip
> which is helpful when dealing with a terminal that
> gets into a strange state is to press return then
> type in reset and press return again.

Typing return when you have already half-a-command line
(and are not sure what it is) is somewhat dangerous.

That's OK, it can be a life style. Be sure to keep some
backups around, then :-)

Cheers
-- t


signature.asc
Description: Digital signature


Re: Bash question hard to formulate

2020-08-02 Thread songbird
...

  i'm not familiar with that problem but another tip
which is helpful when dealing with a terminal that
gets into a strange state is to press return then
type in reset and press return again.


  songbird



Re: Bash question hard to formulate

2020-08-02 Thread David Wright
On Sun 02 Aug 2020 at 17:34:07 (+0200), Esteban L wrote:
> 
> I use terminal window/bash quite a bit, and have a quirky behavior on
> Debian, at least not on Mac OS terminal window. I think it's just a
> default issue, that can be altered -- as I had the exact same problem
> years ago -- that I was able to resolve, which I again turns up. I
> forgot the solution, since it was so simple.
> 
> The question is hard for me to formulate, so I will just describe
> everything, and maybe someone can help?
> 
> What happens:
> 
> I use terminal (in a game or even with ping for simplicity):
> 
> I can type into the terminal.
> 
> I can backspace - as expected.
> 
> However, if i receive new data - my typed text is still in the buffer,
> but is not "echo'd" to a new line. This is more or less OK, UNLESS I
> need to backspace and clear some text. I just can't tell how far I have
> backspaced, since the line is not echoed.
> 
> Maybe best description is:
> 
> I am tying this senten
> 
> 
> 
> ce, and it's fine...but i
> 
> 
> 
> I backspace now, as I want to replace the above line "and it's fine" and
> what comes after it to change it to "it's not fine"
> 
> So, best description is, if i backspace upon receiving new data, I
> cannot see the line that I was typing.
> 
> Any Bash experts able to lend a hand?
> 
> Last time I had this issue, I remember I had to go into .bashrc and
> add/change something. I just don't know what it was.

Is it possible you've been using some facility like that described in
https://www.gnu.org/software/screen/manual/html_node/Flow-Control.html#Flow-Control

Cheers,
David.



Re: Bash question hard to formulate

2020-08-02 Thread Esteban L
Thanks for the tip Andrei!

I am not 100% sure it was .bashrc, it could have been some other config
file, but I am pretty sure it was bash related. it is unfortunately on a
long since gone system.

As to my current system, I have just default settings. I have not
altered anything. I have only tried changing terminal preferences to
getting the desire result.

It's weird. Because on macOS which I don't really want to use, it works
fine. Easy test case is:

launch terminal, ping 8.8.8.8.

In macOS, the current line will just repopulate itself when i hit backspace.

In debian (xterm or terminal), pinging 8.8.8.8, and just putting in
random text does not repopulate on the line i am working on, when i hit
backspace.

I will keep searching for a solution, and send it to the list when I
find it.


On 02.08.20 20:26, Andrei POPESCU wrote:
> On Du, 02 aug 20, 17:34:07, Esteban L wrote:
>> Last time I had this issue, I remember I had to go into .bashrc and
>> add/change something. I just don't know what it was.
> Could it be you changed .inputrc and not .bashrc?
>
> Kind regards,
> Andrei

-- 
https://www.little-beak.com
"Doing what we can."




signature.asc
Description: OpenPGP digital signature


Re: Bash question hard to formulate

2020-08-02 Thread Andrei POPESCU
On Du, 02 aug 20, 17:34:07, Esteban L wrote:
> 
> Last time I had this issue, I remember I had to go into .bashrc and
> add/change something. I just don't know what it was.

Could it be you changed .inputrc and not .bashrc?

Kind regards,
Andrei
-- 
http://wiki.debian.org/FAQsFromDebianUser


signature.asc
Description: PGP signature


Re: Bash question hard to formulate

2020-08-02 Thread Esteban L
Ah now that I analyze the behavior on a MacOS, I see the thing is this:

If I am typing text in, and receive new text, the cursor continues
typing. UNLESS I backspace to the beginning of the (current) line, and
then it echos the previously typed text.

Thanks for the tip! I will try that out.

But, I did solve this at one point in the past, with a bash profile
change, so I know that is possible.

On 02.08.20 17:49, The Wanderer wrote:
> On 2020-08-02 at 11:34, Esteban L wrote:
>
>> Hello,
>>
>> I use terminal window/bash quite a bit, and have a quirky behavior
>> on Debian, at least not on Mac OS terminal window. I think it's just
>> a default issue, that can be altered -- as I had the exact same
>> problem years ago -- that I was able to resolve, which I again turns
>> up. I forgot the solution, since it was so simple.
>>
>> The question is hard for me to formulate, so I will just describe
>> everything, and maybe someone can help?
>>
>> What happens:
>>
>> I use terminal (in a game or even with ping for simplicity):
>>
>> I can type into the terminal.
>>
>> I can backspace - as expected.
>>
>> However, if i receive new data - my typed text is still in the
>> buffer, but is not "echo'd" to a new line. This is more or less OK,
>> UNLESS I need to backspace and clear some text. I just can't tell how
>> far I have backspaced, since the line is not echoed.
>>
>> Maybe best description is:
>>
>> I am tying this senten
>>
>> 
>>
>> ce, and it's fine...but i
>>
>> 
>>
>> I backspace now, as I want to replace the above line "and it's fine"
>> and what comes after it to change it to "it's not fine"
>>
>>
>> So, best description is, if i backspace upon receiving new data, I
>> cannot see the line that I was typing.
> This is a manifestation of the longstanding scenario of "terminal output
> steps all over the shell prompt", and related.
>
> What I usually do, in similar circumstances, is to press first the Up
> arrow and then the Down arrow.
>
> This goes one level up into shell history, so that bash removes the
> currently-displayed in-progress command and displays the
> previously-entered one, and then one level back down, so that bash
> removes the currently-displayed previously-entered command and displays
> the one still in progress.
>
> Not necessarily the best solution, but it usually gets the job done,
> assuming your environment supports this type of history functionality in
> the first place.
>
>> Any Bash experts able to lend a hand?
>>
>> Last time I had this issue, I remember I had to go into .bashrc and 
>> add/change something. I just don't know what it was.
> I have no idea what it could be either. By my understanding of the
> nature of the problem and what leads it to occur, I don't see how any
> bash configuration could possibly avoid it.
>
-- 
https://www.little-beak.com
"Doing what we can."




signature.asc
Description: OpenPGP digital signature


Re: Bash question hard to formulate

2020-08-02 Thread tomas
On Sun, Aug 02, 2020 at 05:34:07PM +0200, Esteban L wrote:
> Hello,

[...]

> Maybe best description is:
> 
> I am tying this senten
> 
> 
> 
> ce, and it's fine...but i
> 
> 
> 
> I backspace now, as I want to replace the above line "and it's fine" and
> what comes after it to change it to "it's not fine"
> 
> 
> So, best description is, if i backspace upon receiving new data, I
> cannot see the line that I was typing.

Apart from The Wanderer's good suggestion, there's always CTRL-L, which
redisplays the typed-line-so-far clearing out everything else (this may
be desired or not).

This will work in other (terminal-ish) contexts, like vi(m) or more/less,
cleaning up when the terminal and the program behind it get confused.

Cheers
-- t


signature.asc
Description: Digital signature


Re: Bash question hard to formulate

2020-08-02 Thread The Wanderer
On 2020-08-02 at 11:34, Esteban L wrote:

> Hello,
> 
> I use terminal window/bash quite a bit, and have a quirky behavior
> on Debian, at least not on Mac OS terminal window. I think it's just
> a default issue, that can be altered -- as I had the exact same
> problem years ago -- that I was able to resolve, which I again turns
> up. I forgot the solution, since it was so simple.
> 
> The question is hard for me to formulate, so I will just describe
> everything, and maybe someone can help?
> 
> What happens:
> 
> I use terminal (in a game or even with ping for simplicity):
> 
> I can type into the terminal.
> 
> I can backspace - as expected.
> 
> However, if i receive new data - my typed text is still in the
> buffer, but is not "echo'd" to a new line. This is more or less OK,
> UNLESS I need to backspace and clear some text. I just can't tell how
> far I have backspaced, since the line is not echoed.
> 
> Maybe best description is:
> 
> I am tying this senten
> 
> 
> 
> ce, and it's fine...but i
> 
> 
> 
> I backspace now, as I want to replace the above line "and it's fine"
> and what comes after it to change it to "it's not fine"
> 
> 
> So, best description is, if i backspace upon receiving new data, I
> cannot see the line that I was typing.

This is a manifestation of the longstanding scenario of "terminal output
steps all over the shell prompt", and related.

What I usually do, in similar circumstances, is to press first the Up
arrow and then the Down arrow.

This goes one level up into shell history, so that bash removes the
currently-displayed in-progress command and displays the
previously-entered one, and then one level back down, so that bash
removes the currently-displayed previously-entered command and displays
the one still in progress.

Not necessarily the best solution, but it usually gets the job done,
assuming your environment supports this type of history functionality in
the first place.

> Any Bash experts able to lend a hand?
> 
> Last time I had this issue, I remember I had to go into .bashrc and 
> add/change something. I just don't know what it was.

I have no idea what it could be either. By my understanding of the
nature of the problem and what leads it to occur, I don't see how any
bash configuration could possibly avoid it.

-- 
   The Wanderer

The reasonable man adapts himself to the world; the unreasonable one
persists in trying to adapt the world to himself. Therefore all
progress depends on the unreasonable man. -- George Bernard Shaw



signature.asc
Description: OpenPGP digital signature


Re: Bash Question

2017-07-06 Thread Greg Wooledge
On Thu, Jul 06, 2017 at 05:25:05PM +1000, David wrote:
> Shells do not set this variable to identify themselves.

> On jessie, 'man 1 login', states that it sets SHELL. I understand this to
> mean that 'login' exports SHELL as an environment variable to child
> processes of 'login'.
> 
> I believe 'login' sets SHELL to the value of the user's login shell, as read
> from /etc/passwd. Once. And after that it does not change.

Yes, this is correct.  The SHELL variable is used by programs like vi
that have a "shell escape" feature, so that they know which shell to
execute.  (And also X terminal emulators, etc.)  It's what shell you
*want*, not what shell you *are*.

Other login-type programs should also export SHELL, including sshd and
the various Display Managers.

If you want to know which shell you're currently in, the best command
I've found so far is:

ps -p $$

Works in Bourne family shells, csh family shells, SysV family ps, and
BSD family ps.  Of course, it's only as accurate as the output of ps,
which a clever user can spoof by overriding argv[0], or by creating
a symlink.

wooledg:~$ (exec -a tentaclesh bash)
wooledg:~$ ps -fp $$
UIDPID  PPID  C STIME TTY  TIME CMD
wooledg  19021  2244  0 07:47 pts/600:00:00 tentaclesh
wooledg:~$ ps -p $$
  PID TTY  TIME CMD
19021 pts/600:00:00 bash

wooledg:~$ ln -s /bin/bash tentaclesh
wooledg:~$ ./tentaclesh
wooledg:~$ ps -p $$
  PID TTY  TIME CMD
19029 pts/600:00:00 tentaclesh
wooledg:~$ ps -fp $$
UIDPID  PPID  C STIME TTY  TIME CMD
wooledg  19029  2244  0 07:51 pts/600:00:00 ./tentaclesh

ps's output is inherently unreliable, but "ps -p $$" with *NO* other
options gives you the best chance you will get.  Still, nothing is
perfect.



Re: Bash Question

2017-07-06 Thread Rainer Dorsch
Am Donnerstag, 6. Juli 2017, 11:50:44 CEST schrieb to...@tuxteam.de:
> On Thu, Jul 06, 2017 at 09:57:50AM +0100, Darac Marjal wrote:
> > On Thu, Jul 06, 2017 at 12:22:29AM +0200, Javier Barroso wrote:
> > >Hi,
> > >
> > >On Wed, Jul 5, 2017 at 11:12 PM, Rainer Dorsch  wrote:
> > >>Hi,
> > >>
> > >>
> > >>
> > >>can anybody help to explain what is going on here ?
> > >>
> > >>
> > >>
> > >>
> > >>
> > >>rd@mohot:~$ echo $SHELL
> > >>/bin/bash
> > >>rd@mohot:~$ if [ "abc" > "dec" ]; then echo bad; fi
> > >>bad
> > >>rd@mohot:~$ if [ "abc" < "dec" ]; then echo good; fi
> > >>good
> > >>rd@mohot:~$
> > >>
> > >>How can abc sort before and after dec at the same time?
> > >
> > >You need to scape "<" and ">":
> > >
> > >if [ "abc" \> "dec" ] ; then ... ;fi
> > >if [ "abc" '>' "dec" ]; then ... ; fi
> > >if [ "abc" ">" "dec" ]; then ... ; fi
> > >
> > >
> > >Delete "dec" file, ( ">" is redirection in bash, so you was creating that
> > >file> 
> > That's a very good point. ">" and "<" are NOT the greater-than/less-than
> > operators in bash.
> 
> They are (in bash: see below!) -- just check bash's manual page under
> "conditional expressions".
> 
> For strings, they list '==' and '=', '!=', '<' and '>'.
> 
> Now *if* you use '[' (single square bracket) as above, you are not using
> bash's built in [this is a little white lie[1], see below], but the external
> command 'test' or some cousin of that (just try "ls -l /usr/bin/[" to see
> what I mean. This one doesn't understand < and >.
> 
> If you want bash's builtin, use '[[' (double square bracket). It's faster
> (one less fork/exec), but also more convenient, because it "knows" that
> there's special syntax inside, so you don't need to escape < and > (as
> someone pointed out in this thread, see (again) below).
> 
> This works:
> 
>   if [[ "abc" < "bcd" ]] ; then  echo "yo" ; else echo "no" ; fi
> 
> Or this
> 
>   if [[ -n "abc" && ( "abc" < "bcd" ) ]] ; then  echo "yo" ; else echo "no"
> ; fi
> 
> (note I didn't have to escape the parens, which would wreak havoc
> elsewhere in the command line, because they have a special meaning
> for the shell, and the shell does expansion before calling commands.
> Only a builtin can achieve that).
> 
> Now try this:
> 
>   if [ "abc" < "bcd" ] ; then  echo "yo" ; else echo "no" ; fi
> 
> (note I chose '<' -- and hope there's no file 'bcd' lying around).
> Then I get:
> 
>   bash: bcd: No such file or directory
> 
> Now this all was a lie :-)
> 
> Or half. The '[' can be a builtin, after all (in bash). You can
> switch that on or off with the enable -- uh -- builtin.
> 
> Just type "help enable" at your favourite bash instance to learn
> about that.
> 
> But the '[' builtin has to behave as far as possible like the
> /usr/bin/[ of yore (aka POSIX 'test'). Including the way the
> shell "expands its innards" before handing things to the command.
> 
> That's why there is [[. Much easier to write and much easier on
> the eye.
> 
> BUT: this all won't work on dash (Debian's preferred non-interactive
> shell: much smaller and faster). There you have to spell things like
> so:
> 
>   if [ "abc" \< "bcd" ] ; then  echo "yo" ; else echo "no" ; fi
> 
> So dash's '[' is a builtin too (remember: /usr/bin/[ doesn't grok
> '<' at all). But dash hasn't the '[[' with its syntactic convenience.
> 
> Hope that helps, somewhat :-)
> 

Many thanks for all the answers (and scaring that kmail just omitted some 
stuff in the Text mail and just included it in the HTML part...this time w/o 
html). They helped a lot to solve my problem...

Thanks again
Rainer

-- 
Rainer Dorsch
http://bokomoko.de/



Re: Bash Question

2017-07-06 Thread tomas
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On Thu, Jul 06, 2017 at 09:57:50AM +0100, Darac Marjal wrote:
> On Thu, Jul 06, 2017 at 12:22:29AM +0200, Javier Barroso wrote:
> >Hi,
> >
> >On Wed, Jul 5, 2017 at 11:12 PM, Rainer Dorsch  wrote:
> >>Hi,
> >>
> >>
> >>
> >>can anybody help to explain what is going on here ?
> >>
> >>
> >>
> >>
> >>
> >>rd@mohot:~$ echo $SHELL
> >>/bin/bash
> >>rd@mohot:~$ if [ "abc" > "dec" ]; then echo bad; fi
> >>bad
> >>rd@mohot:~$ if [ "abc" < "dec" ]; then echo good; fi
> >>good
> >>rd@mohot:~$
> >>
> >>How can abc sort before and after dec at the same time?
> >
> >You need to scape "<" and ">":
> >
> >if [ "abc" \> "dec" ] ; then ... ;fi
> >if [ "abc" '>' "dec" ]; then ... ; fi
> >if [ "abc" ">" "dec" ]; then ... ; fi
> >
> >
> >Delete "dec" file, ( ">" is redirection in bash, so you was creating that 
> >file
> 
> That's a very good point. ">" and "<" are NOT the greater-than/less-than
> operators in bash.

They are (in bash: see below!) -- just check bash's manual page under
"conditional expressions".

For strings, they list '==' and '=', '!=', '<' and '>'.

Now *if* you use '[' (single square bracket) as above, you are not using
bash's built in [this is a little white lie[1], see below], but the external
command 'test' or some cousin of that (just try "ls -l /usr/bin/[" to see
what I mean. This one doesn't understand < and >.

If you want bash's builtin, use '[[' (double square bracket). It's faster
(one less fork/exec), but also more convenient, because it "knows" that
there's special syntax inside, so you don't need to escape < and > (as
someone pointed out in this thread, see (again) below).

This works:

  if [[ "abc" < "bcd" ]] ; then  echo "yo" ; else echo "no" ; fi

Or this

  if [[ -n "abc" && ( "abc" < "bcd" ) ]] ; then  echo "yo" ; else echo "no" ; fi

(note I didn't have to escape the parens, which would wreak havoc
elsewhere in the command line, because they have a special meaning
for the shell, and the shell does expansion before calling commands.
Only a builtin can achieve that).

Now try this:

  if [ "abc" < "bcd" ] ; then  echo "yo" ; else echo "no" ; fi

(note I chose '<' -- and hope there's no file 'bcd' lying around).
Then I get:

  bash: bcd: No such file or directory

Now this all was a lie :-)

Or half. The '[' can be a builtin, after all (in bash). You can
switch that on or off with the enable -- uh -- builtin.

Just type "help enable" at your favourite bash instance to learn
about that.

But the '[' builtin has to behave as far as possible like the
/usr/bin/[ of yore (aka POSIX 'test'). Including the way the
shell "expands its innards" before handing things to the command.

That's why there is [[. Much easier to write and much easier on
the eye.

BUT: this all won't work on dash (Debian's preferred non-interactive
shell: much smaller and faster). There you have to spell things like
so:

  if [ "abc" \< "bcd" ] ; then  echo "yo" ; else echo "no" ; fi

So dash's '[' is a builtin too (remember: /usr/bin/[ doesn't grok
'<' at all). But dash hasn't the '[[' with its syntactic convenience.

Hope that helps, somewhat :-)

Cheers
[1] OK, OK. A dirty grey lie. Read on :-)

- -- tomás
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.12 (GNU/Linux)

iEYEARECAAYFAlleB/QACgkQBcgs9XrR2kZQqgCfbCXMBkw2vwJd2xtfqNSc2/bI
NBkAn1MM8uGnehVTxNQWAP07ptBwJSI9
=r8rB
-END PGP SIGNATURE-



Re: Bash Question

2017-07-06 Thread Darac Marjal

On Thu, Jul 06, 2017 at 12:22:29AM +0200, Javier Barroso wrote:

Hi,

On Wed, Jul 5, 2017 at 11:12 PM, Rainer Dorsch  wrote:

Hi,



can anybody help to explain what is going on here ?





rd@mohot:~$ echo $SHELL
/bin/bash
rd@mohot:~$ if [ "abc" > "dec" ]; then echo bad; fi
bad
rd@mohot:~$ if [ "abc" < "dec" ]; then echo good; fi
good
rd@mohot:~$

How can abc sort before and after dec at the same time?


You need to scape "<" and ">":

if [ "abc" \> "dec" ] ; then ... ;fi
if [ "abc" '>' "dec" ]; then ... ; fi
if [ "abc" ">" "dec" ]; then ... ; fi


Delete "dec" file, ( ">" is redirection in bash, so you was creating that file


That's a very good point. ">" and "<" are NOT the greater-than/less-than
operators in bash. [ "abc" > "dec" ] tests whether the result of "abc"
can be written to the file "dec". Note, however, the subtle difference
between, say [ echo "abc" > "dec" ] where echo executes and copies its
arguments to stdout, which is then written to the file - the success of
this operation is tested; [ "abc" > "dec" ] will try to run "abc". It
looks like bash will interpret the string as a command, so this is
equivalent to [ abc > dec ], i.e. running the command "abc" and
redirecting its output to the file "dec".

The correct operators are actually "-lt" and "-gt". However, these
operators only work on INTEGERs. If you really need to test for "sorts
before", then you may need to resort to using sort itself. 



Regards



--
For more information, please reread.


signature.asc
Description: PGP signature


Re: Bash Question

2017-07-06 Thread David
On 6 July 2017 at 07:53, der.hans  wrote:
>
> "$SHELL" is a builtin variable that tells you what shell you're currently
> running.

No, that's "not accurate", as indeed you wrote later.

Shells do not set this variable to identify themselves.

This can be easily tested by starting any shell interactively and inspecting
$SHELL.

For example, in a terminal start a 'dash' shell and then run 'echo $SHELL'
inside it.

For more enlightenment, start a 'dash' shell with 'SHELL=foo dash' and
run 'echo $SHELL' inside it.

Below I refer to man pages (on jessie). I have not read any relevant
source code, nor do I know if systemd does anything different, someone
else is welcome to comment on that.

On jessie, 'man 1 login', states that it sets SHELL. I understand this to
mean that 'login' exports SHELL as an environment variable to child
processes of 'login'.

I believe 'login' sets SHELL to the value of the user's login shell, as read
from /etc/passwd. Once. And after that it does not change.

And 'man bash' states that 'bash' sets SHELL only if it was previously not
set, and that in that situation it sets SHELL to the value of the user's login
shell.

And 'man dash' doesn't mention SHELL, so I presume it does not touch
it at all.

> When using subshells ( including a shell script ) I find it to
> not be accurate. Could well be that I just don't consistently quote it
> properly.

It is accurate, just not in the way you imagined. Quoting isn't the reason :)

It is simply that the "shell you're currently running" can easily be different
to the login shell, which is what $SHELL is expected to contain.



Re: Bash Question

2017-07-05 Thread Jonathan Marquardt
On Wed, Jul 05, 2017 at 10:31:02PM +, der.hans wrote:
> Am 06. Jul, 2017 schwätzte Jonathan Marquardt so:
> 
> > On Wed, Jul 05, 2017 at 09:53:15PM +, der.hans wrote:
> > > When running the command, your current shell evaluates the variable and
> > > replaces it with the variable's value before starting the echo command.
> > > When echo is run the command has already turned into "echo /bin/bash" or
> > > whatever your shell is, then echo produces "/bin/bash" as the output.
> > 
> > Yes, I thnk that OP's problem is that there is no output, probably because 
> > the
> > variable is not declared or empty.
> 
> Javier's response hints at the mystery.
> 
> The plain text version of the email stopped after the "echo $SHELL" line,
> but there are a couple if statements and a question in the html version.

Wow! Indeed, the plain text version is missig something. Another reason to
follow the netiquette and stop sending these stupid HTML mails...



Re: Bash Question

2017-07-05 Thread Phil Wyett
On Wed, 2017-07-05 at 23:12 +0200, Rainer Dorsch wrote:
> Hi,
>  
> can anybody help to explain what is going on here ?
>  
>  
> rd@mohot:~$ echo $SHELL 
> /bin/bash 
> rd@mohot:~$ if [ "abc" > "dec" ]; then echo bad; fi   
> bad 
> rd@mohot:~$ if [ "abc" < "dec" ]; then echo good; fi 
> good 
> rd@mohot:~$ 
> 
> How can abc sort before and after dec at the same time?
>  
> Thanks
> Rainer
>  
>  
> -- 
> Rainer Dorsch
> http://bokomoko.de/


Hi,

Not sure what you are exactly trying to accomplish and you may need
to explain further.

If you want to basic string compare:

if [[ "abc" < "dec" ]]; then echo true; else echo false; fi

Regards

Phil

-- 
*** If this is a mailing list, I am subscribed, no need to CC me.***

Playing the game for the games sake.

Web: https://kathenas.org

Twitter: kathenasorg

Instagram: kathenasorg

signature.asc
Description: This is a digitally signed message part


Re: Bash Question

2017-07-05 Thread der.hans

Am 06. Jul, 2017 schwätzte Jonathan Marquardt so:


On Wed, Jul 05, 2017 at 09:53:15PM +, der.hans wrote:

When running the command, your current shell evaluates the variable and
replaces it with the variable's value before starting the echo command.
When echo is run the command has already turned into "echo /bin/bash" or
whatever your shell is, then echo produces "/bin/bash" as the output.


Yes, I thnk that OP's problem is that there is no output, probably because the
variable is not declared or empty.


Javier's response hints at the mystery.

The plain text version of the email stopped after the "echo $SHELL" line,
but there are a couple if statements and a question in the html version.

ciao,

der.hans
--
#  https://www.LuftHans.com/https://www.PhxLinux.org/
#  "So the environment is not a luxury ... It is an economically important
#  insurance policy whose wisdom we ignore at our peril."
#  -- Klaus Toepfer, U.N. environment agency Executive Director

Re: Bash Question

2017-07-05 Thread Javier Barroso
Hi,

On Wed, Jul 5, 2017 at 11:12 PM, Rainer Dorsch  wrote:
> Hi,
>
>
>
> can anybody help to explain what is going on here ?
>
>
>
>
>
> rd@mohot:~$ echo $SHELL
> /bin/bash
> rd@mohot:~$ if [ "abc" > "dec" ]; then echo bad; fi
> bad
> rd@mohot:~$ if [ "abc" < "dec" ]; then echo good; fi
> good
> rd@mohot:~$
>
> How can abc sort before and after dec at the same time?

You need to scape "<" and ">":

if [ "abc" \> "dec" ] ; then ... ;fi
if [ "abc" '>' "dec" ]; then ... ; fi
if [ "abc" ">" "dec" ]; then ... ; fi


Delete "dec" file, ( ">" is redirection in bash, so you was creating that file

Regards



Re: Bash Question

2017-07-05 Thread Jonathan Marquardt
On Wed, Jul 05, 2017 at 09:53:15PM +, der.hans wrote:
> When running the command, your current shell evaluates the variable and
> replaces it with the variable's value before starting the echo command.
> When echo is run the command has already turned into "echo /bin/bash" or
> whatever your shell is, then echo produces "/bin/bash" as the output.

Yes, I thnk that OP's problem is that there is no output, probably because the 
variable is not declared or empty.



Re: Bash Question

2017-07-05 Thread der.hans

Am 05. Jul, 2017 schwätzte Rainer Dorsch so:

moin moin Rainer,


can anybody help to explain what is going on here ?


rd@mohot:~$ echo $SHELL


Not sure what level you're asking about, so I will cover a couple levels
of information. Read the ones that are appropriate :).

echo is a a command that repeats back text.

"$SHELL" is a builtin variable that tells you what shell you're currently
running. When using subshells ( including a shell script ) I find it to
not be accurate. Could well be that I just don't consistently quote it
properly.

When running the command, your current shell evaluates the variable and
replaces it with the variable's value before starting the echo command.
When echo is run the command has already turned into "echo /bin/bash" or
whatever your shell is, then echo produces "/bin/bash" as the output.

ciao,

der.hans
--
#  https://www.LuftHans.com/https://www.PhxLinux.org/
#  "It is appallingly obvious that our technology exceeds our humanity."
#   -- Einstein

Re: Bash Question

2017-07-05 Thread Sven Joachim
On 2017-07-05 23:12 +0200, Rainer Dorsch wrote:

> Hi,
>
> can anybody help to explain what is going on here ?
>
>
> rd@mohot:~$ echo $SHELL 

Without any information how you started your shell, it's hard to tell.
For example, xterm version 321 had the bug that it would clear the SHELL
variable from the environment, but that was quickly detected and
corrected[1].

Cheers,
   Sven


1. https://bugs.debian.org/809646



Re: Bash question: get output as a variable?

2010-02-06 Thread Mart Frauenlob
On 04.02.2010 23:09, Dotan Cohen wrote:
 I'm scripting a backup solution, the line that does the business looks
 like this:
 
 tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
 dd of=$(hostname)-$(date +%Y%m%d).tbz
 
 Because of the v flag tar writes to stdout the name of each file
 copied. How can I get that output redirected to a variable, to use
 later in the script?
 
 Thanks!
 

After reading many of the follow-ups, I'd suggest something like that:

#!/bin/bash

# create the archive local first, as if you use 'tar -v' and redirection
# of stderr, you will also catch (possible) error messages of tar, not
# only a file list.

tar -czf archive.tgz

# now list the content with 'tar -t'.
# that ensures that we work only with files, which are in the archive.
# you can put it into an array, or if that's not save enough (as the
# array could become quite big and consume a lot of memory) redirect
# the output to a file.

array=( $(tar -tf archive.tgz) )

# or
tar -tf archive.tgz  file.list

# now do whatever work with the file list, either from the array or
# from the file.

: ...

Best regards

Mart


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-06 Thread Javier Barroso
On Fri, Feb 5, 2010 at 7:10 PM, Chris Jackson c.jack...@shadowcat.co.uk wrote:
 Dotan Cohen wrote:

 I'm scripting a backup solution, the line that does the business looks
 like this:

 tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
 dd of=$(hostname)-$(date +%Y%m%d).tbz

 Because of the v flag tar writes to stdout the name of each file
 copied. How can I get that output redirected to a variable, to use
 later in the script?

 Thanks!



 Use $() like you do with the date command. You have to redirect stderr back
 to stdout, which means running it in a subshell:


 FILES=$( ( tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k
 $1 | dd of=$(hostname)-$(date +%Y%m%d).tbz ) 21 )

 It may cause unexpected results if there're spaces in the filenames though.

If there are spaces in filenames, you can try:

$ n=0; while read l; do files[n]=$l; ((n++)); done  ((tar -zvcf -
* | openssl  $(hostname)-$(date +%Y%m%d)) 21)

Regards,


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-06 Thread Mart Frauenlob
On 06.02.2010 14:17, Javier Barroso wrote:
 On Fri, Feb 5, 2010 at 7:10 PM, Chris Jackson c.jack...@shadowcat.co.uk 
 wrote:
 Dotan Cohen wrote:

 I'm scripting a backup solution, the line that does the business looks
 like this:

 tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
 dd of=$(hostname)-$(date +%Y%m%d).tbz

 Because of the v flag tar writes to stdout the name of each file
 copied. How can I get that output redirected to a variable, to use
 later in the script?

 Thanks!



 Use $() like you do with the date command. You have to redirect stderr back
 to stdout, which means running it in a subshell:


 FILES=$( ( tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k
 $1 | dd of=$(hostname)-$(date +%Y%m%d).tbz ) 21 )

 It may cause unexpected results if there're spaces in the filenames though.
 
 If there are spaces in filenames, you can try:
 
 $ n=0; while read l; do files[n]=$l; ((n++)); done  ((tar -zvcf -
 * | openssl  $(hostname)-$(date +%Y%m%d)) 21)
 
 Regards,
 
 
Warning:

~# read  (printf %s\n  foo bar )
~# printf '%s'\n' $REPLY
' foo bar '
~# read l  (printf %s\n  foo bar )
~# printf '%s'\n' $l
'foo bar'

read strips of leading and trailing spaces.
use the $REPLY variable to avoid that.

rare conditions of newline in filenames is not covered...

Best regards

Mart



-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-06 Thread Mart Frauenlob
On 06.02.2010 13:39, Mart Frauenlob wrote:
 On 04.02.2010 23:09, Dotan Cohen wrote:
 I'm scripting a backup solution, the line that does the business looks
 like this:

 tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
 dd of=$(hostname)-$(date +%Y%m%d).tbz

 Because of the v flag tar writes to stdout the name of each file
 copied. How can I get that output redirected to a variable, to use
 later in the script?

 Thanks!

 
 After reading many of the follow-ups, I'd suggest something like that:
 
 #!/bin/bash
 
 # create the archive local first, as if you use 'tar -v' and redirection
 # of stderr, you will also catch (possible) error messages of tar, not
 # only a file list.
 
 tar -czf archive.tgz
 
 # now list the content with 'tar -t'.
 # that ensures that we work only with files, which are in the archive.
 # you can put it into an array, or if that's not save enough (as the
 # array could become quite big and consume a lot of memory) redirect
 # the output to a file.
 

forgot:
oifs=$IFS
IFS='$\n'

 array=( $(tar -tf archive.tgz) )
 
 # or
 tar -tf archive.tgz  file.list
 


If filename contains newline the whole thing still is in trouble though.



-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-06 Thread Mart Frauenlob
On 06.02.2010 15:43, Mart Frauenlob wrote:
 On 06.02.2010 14:17, Javier Barroso wrote:
 On Fri, Feb 5, 2010 at 7:10 PM, Chris Jackson c.jack...@shadowcat.co.uk 
 wrote:
 Dotan Cohen wrote:

 I'm scripting a backup solution, the line that does the business looks
 like this:

 tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
 dd of=$(hostname)-$(date +%Y%m%d).tbz

 Because of the v flag tar writes to stdout the name of each file
 copied. How can I get that output redirected to a variable, to use
 later in the script?

 Thanks!



 Use $() like you do with the date command. You have to redirect stderr back
 to stdout, which means running it in a subshell:


 FILES=$( ( tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k
 $1 | dd of=$(hostname)-$(date +%Y%m%d).tbz ) 21 )

 It may cause unexpected results if there're spaces in the filenames though.

 If there are spaces in filenames, you can try:

 $ n=0; while read l; do files[n]=$l; ((n++)); done  ((tar -zvcf -
 * | openssl  $(hostname)-$(date +%Y%m%d)) 21)

 Regards,


 Warning:
 

[..]

 read strips of leading and trailing spaces.
 use the $REPLY variable to avoid that.

or by:
IFS=$'\n'

while IFS=$'\n'; read l [...] ; do ...

 
 rare conditions of newline in filenames is not covered...

 
 


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-05 Thread Alexey Salmin
On Fri, Feb 5, 2010 at 1:20 PM, Javier Barroso javibarr...@gmail.com wrote:
 On Fri, Feb 5, 2010 at 1:06 AM, Stephen Powell zlinux...@wowway.com wrote:
 On Thu, 4 Feb 2010 17:42:45 -0500 (EST), Javier Barroso wrote:
 In this case output goes to stderr, so:

 tar -zcvf - * --exclude-from $EXCLUDES 2 /tmp/data$$ | openssl ...

 Is that something you just have to find out by trial and error?
 I checked the man page for tar, and there's nothing in there about
 the -v output being written to stderr.  I'll take your word for it,
 but in the general case, it's hard to tell.  Since stdout and
 stderr both default to the terminal, and since the doc doesn't
 say, how else would you know other than by trial and error?
 If you are using stdout as tar output, including filenames there will
 corrupt that output, so it is logical that in this case filenames goes
 to stderr.

 Sorry my bad english, I hope you understand my opinion


That's true: programs using stdout for data output certainly have to
use stderr as a way to report any additional info.

Alexey


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-05 Thread Ken Teague
On Thu, Feb 4, 2010 at 2:09 PM, Dotan Cohen dotanco...@gmail.com wrote:
 I'm scripting a backup solution, the line that does the business looks
 like this:

 tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
 dd of=$(hostname)-$(date +%Y%m%d).tbz

 Because of the v flag tar writes to stdout the name of each file
 copied. How can I get that output redirected to a variable, to use
 later in the script?

You probably want to put the data into an array rather than a
variable.  An explanation of how to do so can be found here:
 http://tldp.org/LDP/abs/html/arrays.html

Scroll down to the end of Example 26-7 (just about Example 26-8).
Basically, direct stdout to a file, then cat the file to add it to an
array.

snip
The array=( element1 element2 ... elementN )  initialization
operation, with the help of command substitution, makes it possible to
load the contents of a text file into an array.

#!/bin/bash

filename=sample_file

#cat sample_file
#
#1 a b c
#2 d e fg


declare -a array1

array1=( `cat $filename`)#  Loads contents
# List file to stdout  #+ of $filename into array1.
#
#  array1=( `cat $filename | tr '\n' ' '`)
#change linefeeds in file to spaces.
#  Not necessary because Bash does word splitting,
#+ changing linefeeds to spaces.

echo ${arra...@]}# List the array.
#  1 a b c 2 d e fg
#
#  Each whitespace-separated word in the file
#+ has been assigned to an element of the array.

element_count=${#array1[*]}
echo $element_count  # 8
snip


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-05 Thread bruno

Ken Teague wrote:

On Thu, Feb 4, 2010 at 2:09 PM, Dotan Cohen dotanco...@gmail.com wrote:
  

I'm scripting a backup solution, the line that does the business looks
like this:

tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
dd of=$(hostname)-$(date +%Y%m%d).tbz

Because of the v flag tar writes to stdout the name of each file
copied. How can I get that output redirected to a variable, to use
later in the script?



You probably want to put the data into an array rather than a
variable.  An explanation of how to do so can be found here:
 http://tldp.org/LDP/abs/html/arrays.html

Scroll down to the end of Example 26-7 (just about Example 26-8).
Basically, direct stdout to a file, then cat the file to add it to an
array.

snip
The array=( element1 element2 ... elementN )  initialization
operation, with the help of command substitution, makes it possible to
load the contents of a text file into an array.

#!/bin/bash

filename=sample_file

#cat sample_file
#
#1 a b c
#2 d e fg


declare -a array1

array1=( `cat $filename`)#  Loads contents
# List file to stdout  #+ of $filename into array1.
#
#  array1=( `cat $filename | tr '\n' ' '`)
#change linefeeds in file to spaces.
#  Not necessary because Bash does word splitting,
#+ changing linefeeds to spaces.

echo ${arra...@]}# List the array.
#  1 a b c 2 d e fg
#
#  Each whitespace-separated word in the file
#+ has been assigned to an element of the array.

element_count=${#array1[*]}
echo $element_count  # 8
snip


  

Why not simply use the  t option for content listing :

tar tvf  * --exclude-from $EXCLUDES

Bruno



--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org




Re: Bash question: get output as a variable?

2010-02-05 Thread Mart Frauenlob
On 05.02.2010 09:07, Ken Teague wrote:
 On Thu, Feb 4, 2010 at 2:09 PM, Dotan Cohen dotanco...@gmail.com wrote:
 I'm scripting a backup solution, the line that does the business looks
 like this:

 tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
 dd of=$(hostname)-$(date +%Y%m%d).tbz

 Because of the v flag tar writes to stdout the name of each file
 copied. How can I get that output redirected to a variable, to use
 later in the script?
 
 You probably want to put the data into an array rather than a
 variable.  An explanation of how to do so can be found here:
  http://tldp.org/LDP/abs/html/arrays.html
 
 #!/bin/bash

tar ... 2 $filename
mapfile array1  $filename

(don't know actually why '-u 2' option for mapfile does not complete for
me? would make it a 'one-liner'.)

on bash4.0+

regards

Mart


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-05 Thread Stephen Powell
On Fri, 5 Feb 2010 02:20:48 -0500 (EST), Javier Barroso wrote:
 If you are using stdout as tar output, including filenames there will
 corrupt that output, so it is logical that in this case filenames goes
 to stderr.

That does make sense, now that I think about it.  I didn't look
closely enough.  I saw what I expected to see.  The extracted
files themselves always go to disk.  But they don't in this
case.  Thanks.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-05 Thread Ken Teague
On Fri, Feb 5, 2010 at 12:39 AM, bruno bruno.deb...@cyberoso.com wrote:
 Why not simply use the  t option for content listing :

 tar tvf  * --exclude-from $EXCLUDES

He's already creating the archive with -v.  Why process the archive a
2nd time just to get a listing when it comes from stdout the 1st time?


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-05 Thread bruno

Ken Teague wrote:

On Fri, Feb 5, 2010 at 12:39 AM, bruno bruno.deb...@cyberoso.com wrote:
  

Why not simply use the  t option for content listing :

tar tvf  * --exclude-from $EXCLUDES



He's already creating the archive with -v.  Why process the archive a
2nd time just to get a listing when it comes from stdout the 1st time?


  

because it's a simplier way to get the list into a variable
because the script gets much clearer
because it is not safe to rely on stderr since it is supposed to display 
errors, which it might do as well
because he would get the list of the files that have really been 
compressed, not just the processed ones
because the overhead may not be worth the complication of trying to do 
both things at the same time
because he might as well never use the v option (it's not useful in my 
proposition either, and it would even reduce the overhead)


because it is another way to do it and nobody had proposed it before


Bruno


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org




Re: Bash question: get output as a variable?

2010-02-05 Thread Paul E Condon
On 20100205_135919, Alexey Salmin wrote:
 On Fri, Feb 5, 2010 at 1:20 PM, Javier Barroso javibarr...@gmail.com wrote:
  On Fri, Feb 5, 2010 at 1:06 AM, Stephen Powell zlinux...@wowway.com wrote:
  On Thu, 4 Feb 2010 17:42:45 -0500 (EST), Javier Barroso wrote:
  In this case output goes to stderr, so:
 
  tar -zcvf - * --exclude-from $EXCLUDES 2 /tmp/data$$ | openssl ...
 
  Is that something you just have to find out by trial and error?
  I checked the man page for tar, and there's nothing in there about
  the -v output being written to stderr. ?I'll take your word for it,
  but in the general case, it's hard to tell. ?Since stdout and
  stderr both default to the terminal, and since the doc doesn't
  say, how else would you know other than by trial and error?
  If you are using stdout as tar output, including filenames there will
  corrupt that output, so it is logical that in this case filenames goes
  to stderr.
 
  Sorry my bad english, I hope you understand my opinion
 
 
 That's true: programs using stdout for data output certainly have to
 use stderr as a way to report any additional info.
 
 Alexey

A comment towards 'how would I know':

Traditional Unix and traditional C both made provision for stdin,
stdout, and stderr. When Stroustrup, et al., started working on C++
and its earlier predicessors, someone recognized the need for a fourth
stdXXX, namely stdlog.  I think it was/is a good idea, but it has
never gained enough traction to justify all the changes that would be
required if it were introduced into the POSIX standard. Instead, the
community has kept the name stderr, but changed the usage to something
that might better be named stdmsg, indicating both errors and action
logging. Its the sort of historical development that doesn't get recorded
in any man page (or at least any man page that newbies know about).

HTH
-- 
Paul E Condon   
pecon...@mesanetworks.net


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-05 Thread Bob McGowan
Dotan Cohen wrote:
 I'm scripting a backup solution, the line that does the business looks
 like this:
 
 tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
 dd of=$(hostname)-$(date +%Y%m%d).tbz
 
 Because of the v flag tar writes to stdout the name of each file
 copied. How can I get that output redirected to a variable, to use
 later in the script?
 
 Thanks!
 

I would avoid trying to store the file listing in any type of variable,
since you have no idea how big the list will be.

And, as others have noted, in the above case the file names list is sent
to stderr, so it doesn't mess up the stdout you requested for the
archive data.

I'd recommend using a named pipe, or FIFO, like this:

  mknod filenames p
  tar -zcvf - *  --exclude-from $EXCLUDES 2filenames  |
  openssl ... | dd ... 

NOTE:  the '2filenames' and the ampersand to put the command into the
background.

Then, later in the script, you would do something like this:

while read filename
do
  # other work
done  filenames

I've not done the above with anything large enough to know, but the way
a FIFO works, the read loop will block, waiting for input, if it
exhausts the FIFO content.  The FIFO will generate a zero length read
after the last line from tar is captured which will terminate the loop.

-- 
Bob McGowan


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-05 Thread Bob McGowan
Dotan Cohen wrote:
 I'm scripting a backup solution, the line that does the business looks
 like this:
 
 tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
 dd of=$(hostname)-$(date +%Y%m%d).tbz
 
 Because of the v flag tar writes to stdout the name of each file
 copied. How can I get that output redirected to a variable, to use
 later in the script?
 
 Thanks!
 

I forgot to ask, in the last post:  Why are you using the 'dd' command?

I would think you could do:

  tar ... | openssl ...  $(hostname)-$(date +%Y%m%d).tbz

-- 
Bob McGowan
Symantec
US Internationalization


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-05 Thread Chris Jackson

Dotan Cohen wrote:


I'm scripting a backup solution, the line that does the business looks
like this:

tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
dd of=$(hostname)-$(date +%Y%m%d).tbz

Because of the v flag tar writes to stdout the name of each file
copied. How can I get that output redirected to a variable, to use
later in the script?

Thanks!




Use $() like you do with the date command. You have to redirect stderr 
back to stdout, which means running it in a subshell:



FILES=$( ( tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt 
-k $1 | dd of=$(hostname)-$(date +%Y%m%d).tbz ) 21 )


It may cause unexpected results if there're spaces in the filenames though.

--
Chris Jackson
Shadowcat Systems Ltd.


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org




Re: Bash question: get output as a variable?

2010-02-05 Thread Boyd Stephen Smith Jr.
On Friday 05 February 2010 10:01:45 Paul E Condon wrote:
 Traditional Unix and traditional C both made provision for stdin,
 stdout, and stderr. When Stroustrup, et al., started working on C++
 and its earlier predicessors, someone recognized the need for a fourth
 stdXXX, namely stdlog.

If you system provides stdlog (or a C++ equivalent), it is likely still file 
descriptor 2, but opened in line-buffered mode.  stderr (and cerr) is supposed 
to be opened in non-buffered mode.
-- 
Boyd Stephen Smith Jr.   ,= ,-_-. =.
b...@iguanasuicide.net  ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/\_/


signature.asc
Description: This is a digitally signed message part.


Re: Bash question: get output as a variable?

2010-02-05 Thread Brian Ryans
Quoting Stephen Powell on 2010-02-04 18:06:58:
 but in the general case, it's hard to tell.  Since stdout and
 stderr both default to the terminal, and since the doc doesn't
 say, how else would you know other than by trial and error?

Trial and error is an effective way to figure it out. [1] Depending on a
few factors though, it may be more instructive long-term to read the
source. I've recently been putting that philosophy to use in various
things where the documentation's not quite clear. Both methods have
their merits.

[1] possibly redirect std{out,err} to separate temp files and view them?

-- 
 _  Brian Ryans 8B2A 54C4 E275 8CFD 8A7D 5D0B 0AD0 B014 C112 13D0 .
( ) ICQ UIN: 43190205 | Mail/MSN/Jabber: brianlry...@gmail.com   ..:
 X  ASCII Ribbon Campaign Against HTML mail and v-cards: asciiribbon.org
/ \ Any technology distinguishable from magic is insufficently advanced.


signature.asc
Description: Digital signature


Re: Bash question: get output as a variable?

2010-02-05 Thread Ken Teague
On Fri, Feb 5, 2010 at 7:44 AM, bruno bruno.deb...@cyberoso.com wrote:
 because it's a simplier way to get the list into a variable

Can you please explain how it's simpler.  The method I suggested
certainly isn't as easy, but the method I suggested merely showed a
detailed example.  Others here are coming up with 1 or 2 liners that
can do this without having to process the archive a 2nd time.

I don't see how the example you provided puts the list into a
variable.  Would you be so kind as to go into more detail regarding
your suggestion?


 because the script gets much clearer

I agree that your suggestion would be much clearer, and your
suggestion may suit the needs of the OP.  I suppose it's just my
personal feelings to not sacrifice efficiency for making a script
easier to understand.  Comments can be added to the script to explain
how parts of it function.


 because it is not safe to rely on stderr since it is supposed to display
 errors, which it might do as well

Others have recommended stderr.  I'm not sure why.  The method that
would be most effective would be to direct stdout, not stderr.

it...@mybox:~$ ls -l
-rw-r--r-- 1 itsme itsme 0 2010-02-05 14:54 file1
-rw-r--r-- 1 itsme itsme 0 2010-02-05 14:54 file2
-rw-r--r-- 1 itsme itsme 0 2010-02-05 14:54 file3
-rw--- 1 root   root0 2010-02-05 14:53 somefile
it...@mybox:~$ tar cvf test.tar somefile file1 file2 file3 out.txt
tar: somefile: Cannot open: Permission denied
tar: Error exit delayed from previous errors
it...@mybox:~$ cat out.txt
file1
file2
file3


 because he would get the list of the files that have really been compressed,
 not just the processed ones

Not if he uses stdout.  The example shown above only shows what was
added to the tar file.


 because the overhead may not be worth the complication of trying to do both
 things at the same time

Efficiency vs clarity; sometimes it's a personal preference, other
times it may not be.  For example, if I'm passing this script on to
someone else that isn't familiar with the scripting language, I think
clarity would be paramount.  Otherwise, I'd go for efficiency.


 because he might as well never use the v option (it's not useful in my
 proposition either, and it would even reduce the overhead)

The method you suggested is to process the archive a 2nd time to get
the listing, and to use -tv.  That causes more overhead than getting
the list of processed files while the archive is being created.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-05 Thread Ken Teague
On Fri, Feb 5, 2010 at 10:10 AM, Chris Jackson
c.jack...@shadowcat.co.uk wrote:
 Use $() like you do with the date command. You have to redirect stderr back
 to stdout, which means running it in a subshell:


 FILES=$( ( tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k
 $1 | dd of=$(hostname)-$(date +%Y%m%d).tbz ) 21 )

 It may cause unexpected results if there're spaces in the filenames though.

I think this is the best method I've seen thus far.  Putting the data
into an array should avoid problems with file names containing spaces.
 I don't understand why he would stderr in it, though.  I'd like to
know what the OP plans to do with the list of processed files.


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-05 Thread Tony Nelson
On 10-02-04 19:06:58, Stephen Powell wrote:
 On Thu, 4 Feb 2010 17:42:45 -0500 (EST), Javier Barroso wrote:
  In this case output goes to stderr, so:
  
  tar -zcvf - * --exclude-from $EXCLUDES 2 /tmp/data$$ | openssl ...
 
 Is that something you just have to find out by trial and error?
 I checked the man page for tar, and there's nothing in there about
 the -v output being written to stderr.  I'll take your word for it,
 but in the general case, it's hard to tell.  Since stdout and
 stderr both default to the terminal, and since the doc doesn't
 say, how else would you know other than by trial and error?

As the man page notes, see `info tar`.  The answer is buried in 3.9 
Asking for Confirmation During Operations.

-- 

TonyN.:'   mailto:tonynel...@georgeanelson.com
  '  http://www.georgeanelson.com/


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-05 Thread Ken Teague
On Fri, Feb 5, 2010 at 12:42 AM, Mart Frauenlob
mart.frauen...@chello.at wrote:
 tar ... 2 $filename
 mapfile array1  $filename

 (don't know actually why '-u 2' option for mapfile does not complete for
 me? would make it a 'one-liner'.)

 on bash4.0+


This is a great example as well.  The only problem is bash4 isn't
readily available to people using lenny.  Also, wouldn't he just want
to redirect sdtout and not stderr?  I guess it all depends on what he
wants to do with the list.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-05 Thread Bob McGowan
Ken Teague wrote:
 On Fri, Feb 5, 2010 at 10:10 AM, Chris Jackson
 c.jack...@shadowcat.co.uk wrote:
 Use $() like you do with the date command. You have to redirect stderr back
 to stdout, which means running it in a subshell:


 FILES=$( ( tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k
 $1 | dd of=$(hostname)-$(date +%Y%m%d).tbz ) 21 )

 It may cause unexpected results if there're spaces in the filenames though.
 
 I think this is the best method I've seen thus far.  Putting the data
 into an array should avoid problems with file names containing spaces.
  I don't understand why he would stderr in it, though.  I'd like to
 know what the OP plans to do with the list of processed files.
 
 

As noted in some earlier posts, using 'tar -f -' causes the archive tar
creates to be written to stdout.

This means the list of file names printed because of the 'v' option,
must be written to some other file descriptor, else it will corrupt the
archive contents.

The usual way for an app to do this is to write to stderr, which is
what 'tar' does.

The tar sdtout is already redirected in the initial pipeline.  Putting
the pipeline in parenthesis causes the entire thing to run in a
subshell.  The '21' takes the stderr of the subshell and puts it onto
the stdout of the current shell, which is then redirected by the $(...)
into the variable.

-- 
Bob McGowan


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-04 Thread Alex Samad
On Fri, Feb 05, 2010 at 12:09:28AM +0200, Dotan Cohen wrote:
 I'm scripting a backup solution, the line that does the business looks
 like this:
 
 tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
 dd of=$(hostname)-$(date +%Y%m%d).tbz
 
 Because of the v flag tar writes to stdout the name of each file
 copied. How can I get that output redirected to a variable, to use
 later in the script?

not sure you can, as you are pushing the tar output via stdout as well.
maybe use a fifo to communicate between tar and openssl

Alex

 
 Thanks!
 

-- 
Winter is the season in which people try to keep the house as warm as
it was in the summer, when they complained about the heat.


signature.asc
Description: Digital signature


Re: Bash question: get output as a variable?

2010-02-04 Thread Stephen Powell
On Thu, 4 Feb 2010 17:09:28 -0500 (EST), Dotan Cohen wrote:
 I'm scripting a backup solution, the line that does the business looks
 like this:
 
 tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
 dd of=$(hostname)-$(date +%Y%m%d).tbz
 
 Because of the v flag tar writes to stdout the name of each file
 copied. How can I get that output redirected to a variable, to use
 later in the script?

First of all, let me preface my remarks by saying that I am just
learning shell scripting myself and definitely consider myself a
novice.  Some guru out there may (and probably does) know a better
way.

Using a variable is problematic, since a pipeline runs in a subshell
environment.  In fact, each stage of the pipeline is a separate
process.  Thus, any variables set in a pipeline stage do not
affect the values of the corresponding variable names in the shell
environment that invoked the pipeline.

How about something like this?

   tar -zcvf - * --exclude-from $EXCLUDES | tee /tmp/data$$ | \
   openssl ...
   .
   . logic to process the /tmp/data$$ data file
   .
   rm /tmp/data$$
 


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-04 Thread Javier Barroso
On Thu, Feb 4, 2010 at 11:32 PM, Stephen Powell zlinux...@wowway.com wrote:
 On Thu, 4 Feb 2010 17:09:28 -0500 (EST), Dotan Cohen wrote:
 I'm scripting a backup solution, the line that does the business looks
 like this:

 tar -zcvf - *  --exclude-from $EXCLUDES  | openssl des3 -salt -k $1 |
 dd of=$(hostname)-$(date +%Y%m%d).tbz

 Because of the v flag tar writes to stdout the name of each file
 copied. How can I get that output redirected to a variable, to use
 later in the script?

 First of all, let me preface my remarks by saying that I am just
 learning shell scripting myself and definitely consider myself a
 novice.  Some guru out there may (and probably does) know a better
 way.

 Using a variable is problematic, since a pipeline runs in a subshell
 environment.  In fact, each stage of the pipeline is a separate
 process.  Thus, any variables set in a pipeline stage do not
 affect the values of the corresponding variable names in the shell
 environment that invoked the pipeline.

 How about something like this?

   tar -zcvf - * --exclude-from $EXCLUDES | tee /tmp/data$$ | \
   openssl ...
In this case output goes to stderr, so:

tar -zcvf - * --exclude-from $EXCLUDES 2 /tmp/data$$ | openssl ...


   .
   . logic to process the /tmp/data$$ data file
   .
   rm /tmp/data$$



 --
 To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
 with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org




--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-04 Thread Stephen Powell
On Thu, 4 Feb 2010 17:42:45 -0500 (EST), Javier Barroso wrote:
 In this case output goes to stderr, so:
 
 tar -zcvf - * --exclude-from $EXCLUDES 2 /tmp/data$$ | openssl ...

Is that something you just have to find out by trial and error?
I checked the man page for tar, and there's nothing in there about
the -v output being written to stderr.  I'll take your word for it,
but in the general case, it's hard to tell.  Since stdout and
stderr both default to the terminal, and since the doc doesn't
say, how else would you know other than by trial and error?


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: Bash question: get output as a variable?

2010-02-04 Thread Javier Barroso
On Fri, Feb 5, 2010 at 1:06 AM, Stephen Powell zlinux...@wowway.com wrote:
 On Thu, 4 Feb 2010 17:42:45 -0500 (EST), Javier Barroso wrote:
 In this case output goes to stderr, so:

 tar -zcvf - * --exclude-from $EXCLUDES 2 /tmp/data$$ | openssl ...

 Is that something you just have to find out by trial and error?
 I checked the man page for tar, and there's nothing in there about
 the -v output being written to stderr.  I'll take your word for it,
 but in the general case, it's hard to tell.  Since stdout and
 stderr both default to the terminal, and since the doc doesn't
 say, how else would you know other than by trial and error?
If you are using stdout as tar output, including filenames there will
corrupt that output, so it is logical that in this case filenames goes
to stderr.

Sorry my bad english, I hope you understand my opinion


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: bash question

2009-10-10 Thread Boyd Stephen Smith Jr.
In 20091010042217.gd2...@samad.com.au, Alex Samad wrote:
Hi

i have this

RDSCHM=--remote-schema 'ssh -i /root/.ssh/id_backup -C  %s
rdiff-backup  --server'


and trying this

rdiff-backup \
   $RDSCHM \
   $RDRM \
   $DEST/

Sorry, there's no clean, portable way to have both multiple command-line 
arguments in a single variable and have an IFS character in one of those 
arguments.

When you do this rdiff-backup gets these arguments:
argv = {
 [0] = rdiff-backup
 [1] = --remote-schema
 [2] = 'ssh
 [3] = -i
 [4] = /root/.ssh/id_backup
 [5] = -C
 ... /* etc. */
}

If you force your script to be executed with bash (NOT dash or just sh) you 
can use shell arrays to do what you want:

RDSCHM=(
 '--remote-schema'
 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'
)

rdiff-backup \
$rdsc...@] \
$RDRM \
$DEST/


You can also force your to work correctly under dash / sh, but you'll have to 
understand how to use eval, which can get a bit tricky.  It would look 
something like this:

RDSCHM=--remote-schema \
'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'

eval rdiff-backup $RDSCHM $RDRM '$DEST/'
-- 
Boyd Stephen Smith Jr.   ,= ,-_-. =.
b...@iguanasuicide.net   ((_/)o o(\_))
ICQ: 514984 YM/AIM: DaTwinkDaddy `-'(. .)`-'
http://iguanasuicide.net/\_/


signature.asc
Description: This is a digitally signed message part.


Re: bash question

2009-10-10 Thread Alex Samad
On Sat, Oct 10, 2009 at 01:21:30AM -0500, Boyd Stephen Smith Jr. wrote:
 In 20091010042217.gd2...@samad.com.au, Alex Samad wrote:
 Hi
 
 i have this
 
 RDSCHM=--remote-schema 'ssh -i /root/.ssh/id_backup -C  %s
 rdiff-backup  --server'
 
 
 and trying this
 
 rdiff-backup \
  $RDSCHM \
  $RDRM \
  $DEST/
 
 Sorry, there's no clean, portable way to have both multiple command-line 
 arguments in a single variable and have an IFS character in one of those 
 arguments.

Oh well, time to play with IFS or eval

 
 When you do this rdiff-backup gets these arguments:
 argv = {
  [0] = rdiff-backup
  [1] = --remote-schema
  [2] = 'ssh
  [3] = -i
  [4] = /root/.ssh/id_backup
  [5] = -C
  ... /* etc. */
 }
 
 If you force your script to be executed with bash (NOT dash or just sh) you 
 can use shell arrays to do what you want:
 
 RDSCHM=(
  '--remote-schema'
  'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'
 )
 
 rdiff-backup \
   $rdsc...@] \
   $RDRM \
   $DEST/
 
 
 You can also force your to work correctly under dash / sh, but you'll have to 
 understand how to use eval, which can get a bit tricky.  It would look 
 something like this:


I wanted to try and stick to non bashisms

 
 RDSCHM=--remote-schema \
 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup --server'
 
 eval rdiff-backup $RDSCHM $RDRM '$DEST/'

thanks

-- 
We're concerned about AIDS inside our White House -- make no mistake about it.

- George W. Bush
02/07/2001


signature.asc
Description: Digital signature


Re: bash question

2009-10-10 Thread Antonio Perez
Alex Samad wrote:

 Hi, i have this:

 RDSCHM=--remote-schema 'ssh -i /root/.ssh/id_backup -C  %s rdiff-backup 
 --server'

 and trying this
 
 rdiff-backup \
 $RDSCHM \
 $RDRM \
 $DEST/

 with sh -x i get this
 
 + rdiff-backup --remote-schema ''\''ssh' -i /root/.ssh/id_backup -C %s 
 rdiff-backup '--server'\''' --remove-older-than '10B' --force 
 max::/backups/test/system/

I am pretty sure you are using bash as the sh link, do 'ls -la /bin/sh' to get: 
/bin/sh -- /bin/bash
If it were dash the responses would be different.

Testing: set up a test file with:
#!/bin/sh
RDSCHM=--remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup 
--server'
echo $RDSCHM
echo $RDSCHM
with: bash -x test, I get:
+ RDSCHM='--remote-schema '\''ssh -i /root/.ssh/id_backup -C %s 
rdiff-backup --server'\'''
+ echo --remote-schema ''\''ssh' -i /root/.ssh/id_backup 
$'-C\302\240%s' 'rdiff-backup --server'\'''
--remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup 
--server'
+ echo '--remote-schema '\''ssh -i /root/.ssh/id_backup -C %s 
rdiff-backup --server'\'''
--remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup 
--server'

with: dash -x test, I get:
+ RDSCHM=--remote-schema 'ssh -i /root/.ssh/id_backup -C %s 
rdiff-backup --server'
+ echo --remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup 
--server'
--remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup 
--server'
+ echo --remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup 
--server'
--remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup 
--server'

with dash there is no «  ''\''ssh'  »

Also, did you notice the difference between a command on an unquoted variable 
and a quoted one?
+ echo --remote-schema ''\''ssh' -i /root/.ssh/id_backup 
$'-C\302\240%s' 'rdiff-backup --server'\'''
+ echo '--remote-schema '\''ssh -i /root/.ssh/id_backup -C %s 
rdiff-backup --server'\'''

Conclusion: Quoting the variable will solve your problem, as this:
rdiff-backup \
  $RDSCHM \
  $RDRM \
  $DEST/


 the ''\''ssh' is the confusing bit it is seperate out the ssh and the -i.

Yes, on a bash shell, but only while quoting with -x, the actual command does 
the right thing.

 what can I do to prevent this.

Just put « $RDSCHM »  inside quotes as this: « $RDSCHM »

 My reading has lead me to IFS variable
 but I don't want to start playing with this yet ! I think I am just
 missing something. Hopefully the ml eyes will be able to see what i
 can't

No need to

 oh and its using dash well sh

It does not really matter which shell it is, when the issue is about correct 
quoting of variables.

-- 
Antonio Perez


--
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org
with a subject of unsubscribe. Trouble? Contact listmas...@lists.debian.org



Re: bash question

2009-10-10 Thread green
Boyd Stephen Smith Jr. wrote at 2009-10-10 01:21 -0500:
 You can also force your to work correctly under dash / sh, but you'll have to 
 understand how to use eval, which can get a bit tricky.  It would look 
 something like this:

I second the eval suggestion, it has helped me several times to simplify things 
like this.


signature.asc
Description: Digital signature


Re: bash question

2009-10-10 Thread Alex Samad
On Sat, Oct 10, 2009 at 07:45:14AM -0400, Antonio Perez wrote:
 Alex Samad wrote:
 
  Hi, i have this:
 
  RDSCHM=--remote-schema 'ssh -i /root/.ssh/id_backup -C  %s rdiff-backup 
  --server'
 
  and trying this
  
  rdiff-backup \
  $RDSCHM \
  $RDRM \
  $DEST/
 
  with sh -x i get this
  
  + rdiff-backup --remote-schema ''\''ssh' -i /root/.ssh/id_backup -C %s 
  rdiff-backup '--server'\''' --remove-older-than '10B' --force 
  max::/backups/test/system/
 
 I am pretty sure you are using bash as the sh link, do 'ls -la /bin/sh' to 
 get: /bin/sh -- /bin/bash
 If it were dash the responses would be different.

true - I could have sworn I had installed the latest dash package which
moves sh to dash
 
 Testing: set up a test file with:
 #!/bin/sh
 RDSCHM=--remote-schema 'ssh -i /root/.ssh/id_backup -C %s 
 rdiff-backup --server'
 echo $RDSCHM
 echo $RDSCHM
 with: bash -x test, I get:
 + RDSCHM='--remote-schema '\''ssh -i /root/.ssh/id_backup -C %s 
 rdiff-backup --server'\'''
 + echo --remote-schema ''\''ssh' -i /root/.ssh/id_backup 
 $'-C\302\240%s' 'rdiff-backup --server'\'''
 --remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup 
 --server'
 + echo '--remote-schema '\''ssh -i /root/.ssh/id_backup -C %s 
 rdiff-backup --server'\'''
 --remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup 
 --server'
 
 with: dash -x test, I get:
 + RDSCHM=--remote-schema 'ssh -i /root/.ssh/id_backup -C %s 
 rdiff-backup --server'
 + echo --remote-schema 'ssh -i /root/.ssh/id_backup -C %s 
 rdiff-backup --server'
 --remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup 
 --server'
 + echo --remote-schema 'ssh -i /root/.ssh/id_backup -C %s 
 rdiff-backup --server'
 --remote-schema 'ssh -i /root/.ssh/id_backup -C %s rdiff-backup 
 --server'
 
 with dash there is no «  ''\''ssh'  »
 
 Also, did you notice the difference between a command on an unquoted variable 
 and a quoted one?
 + echo --remote-schema ''\''ssh' -i /root/.ssh/id_backup 
 $'-C\302\240%s' 'rdiff-backup --server'\'''
 + echo '--remote-schema '\''ssh -i /root/.ssh/id_backup -C %s 
 rdiff-backup --server'\'''
 
 Conclusion: Quoting the variable will solve your problem, as this:
 rdiff-backup \
   $RDSCHM \
   $RDRM \
   $DEST/

I tried this but then rdiff-backup tried to execute the whole variable
as 1 command and not such command ssh\ -i\ /roo.

 
 
  the ''\''ssh' is the confusing bit it is seperate out the ssh and the -i.
 
 Yes, on a bash shell, but only while quoting with -x, the actual command does 
 the right thing.
 
  what can I do to prevent this.
 
 Just put « $RDSCHM »  inside quotes as this: « $RDSCHM »
 
  My reading has lead me to IFS variable
  but I don't want to start playing with this yet ! I think I am just
  missing something. Hopefully the ml eyes will be able to see what i
  can't
 
 No need to
 
  oh and its using dash well sh
 
 It does not really matter which shell it is, when the issue is about correct 
 quoting of variables.

Thanks I will investigate more

 



signature.asc
Description: Digital signature


Re: Bash question

2003-07-02 Thread Jamin W. Collins
On Tue, Jul 01, 2003 at 06:52:26PM +0100, Colin Watson wrote:
 On Tue, Jul 01, 2003 at 07:43:28AM -0600, Jamin W. Collins wrote:
 
  This has been asked and answered a few times in the past.  There are
  several ways to do it.  Here is one:
  
 #!/bin/sh
 IFS=$'\n'
  
 for FILE in `ls -1`; do
echo $FILE
 done
 
 FYI, Unix filenames are allowed to contain newlines.

Pick up new information every day.  Cool.  The above does still solve
the OP's problem.

-- 
Jamin W. Collins

Linux is not The Answer. Yes is the answer. Linux is The Question. - Neo


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Bash question

2003-07-02 Thread Jon Haugsand
* Shawn Lamson

 for file in `ls`
 do mpg123 $file
 done

Really?


$ touch aa aa
$ touch bb
$ for file in `ls`; do echo $file; done
aa
aa
bb

-- 
 Jon Haugsand, [EMAIL PROTECTED]
 http://www.norges-bank.no


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Bash question

2003-07-02 Thread matt zagrabelny
beating this to death:

#!/bin/bash
IFS=

for file in $(ls -1); do
echo $file
done

cheers,

-matt zagrabelny


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Bash question

2003-07-01 Thread David Z Maze
Stephan Sauerburger [EMAIL PROTECTED] writes:

 In a for loop which runs through all files, as in:

 for file in `ls`
 do
   #stuff
 done

ITYM 'for file in *'...

 ...will do just a fine job, so long as none of the file names have any
 spaces in them.

because it gets around this.  In general, you want to be careful if
you're dealing with files with spaces in their names, since the shell
will be enthusiastic about breaking words.

  for file in *.ogg; do
ogg123 $file
  done

(Since the double-quotes allow variable expansion, but force the
result to be a single world for shell purposes.)

 Then the preceding instructions first try to play Aerosmith, then
 -, then Walk, then This, then Way.mp3, then (They... you get the
 idea. All of which fail, and this could lead to dangerous results if you're
 doing something other than mpg123 to it, like rm, and there were also a
 file simply called Aerosmith.

ISTR earlier versions of Mac OS X, which is built on top of some BSD,
having issues like this as well.

-- 
David Maze [EMAIL PROTECTED]  http://people.debian.org/~dmaze/
Theoretical politics is interesting.  Politicking should be illegal.
-- Abra Mitchell


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Bash question

2003-07-01 Thread Jamin W. Collins
On Tue, Jul 01, 2003 at 02:46:58AM -0500, Stephan Sauerburger wrote:

 So how can one have the for loop separate the elements of the list only by
 newlines (\n), filling the contents of file with the whole line,
 and not separate by spaces, tabs, or other white space?

This has been asked and answered a few times in the past.  There are
several ways to do it.  Here is one:

   #!/bin/sh
   IFS=$'\n'

   for FILE in `ls -1`; do
  echo $FILE
   done
   
-- 
Jamin W. Collins


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Bash question

2003-07-01 Thread Shawn Lamson
On Tue, July 01 at  2:46 AM EDT
Stephan Sauerburger [EMAIL PROTECTED] wrote:

So how can one have the for loop separate the elements of the list only
by newlines (\n), filling the contents of file with the whole line,
and not separate by spaces, tabs, or other white space?

You'll probably get a million responses from this as someone asks it
about every 3 months.  I guess the simplest answer is to protect your
expanded variable name with double quotes.

for file in `ls`
do mpg123 $file
done

HTH

Shawn Lamson
[EMAIL PROTECTED]
Debian GNU/Linux 3.0


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Bash question

2003-07-01 Thread Jon Haugsand
* Stephan Sauerburger
 This is a general shell-scripting question:

 In a for loop which runs through all files, as in:

 for file in `ls`
 do
   #stuff
 done

 How do I have it make sure it iterates file-by-file? The following example, to play 
 all
 mp3s in the current directory:

 for file in `ls`
 do
   mpg123 $file
 done

 ...will do just a fine job, so long as none of the file names have any
 spaces in them. If my directory contained:

The simple and correct solution to just this question is not to use
`ls`, but *:

 for file in *
 do
   mpg123 $file
 done

Note also that you need to quote $file. However, you get anyway into
all sorts of trouble if there are other files, not to say directories
in your directory.

A very failsafe variant is to use find:

find . -type f -print0 | xargs -0 mpg123

-- 
 Jon Haugsand, [EMAIL PROTECTED]
 http://www.norges-bank.no


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Bash question

2003-07-01 Thread thomas . gies
Hi.

Try find. It has the -exec parameter. That is what you want.

-- 
Die Welt ist kunterbunt, mein Arsch wiegt 180 Pfund. - Hans Peter Gies, 1989 



pgp0.pgp
Description: PGP signature


Re: Bash question

2003-07-01 Thread Hugh Saunders
On Tue, Jul 01, 2003 at 10:28:32AM -0400, David Z Maze wrote:
 ITYM 'for file in *'...
 ISTR earlier versions...
flip man! i needed two references to `dict` to read your email.
Guess i should learn some acronyms!

-- 
hugh


pgp0.pgp
Description: PGP signature


Re: Bash question

2003-07-01 Thread Johannes Zarl
   for file in *.ogg; do
 ogg123 $file
   done

 (Since the double-quotes allow variable expansion, but force the
 result to be a single world for shell purposes.)

To deal with all (im)possible filenames, you could even do:
for file in *.ogg 
do
  ogg123 -- $file
done

Just in case you have filenames starting with '-'...

Greetings from the paranoid side ;-)
  Johannes

-- 
More than machinery we need humanity -- Charlie Chaplin, The Great 
Dictator


pgp0.pgp
Description: signature


Re: Bash question

2003-07-01 Thread Lukas Ruf
Jon Haugsand [EMAIL PROTECTED] [2003-07-01 19:43]:
 in your directory.
 
 A very failsafe variant is to use find:
 
 find . -type f -print0 | xargs -0 mpg123

I usually make use of find's parameter

-maxdepth level

if you would like to restrict the search to a certain depth of the
directory tree (man find).

wbr,
Lukas
-- 
Lukas Ruf   | Wanna know anything about raw |
http://www.lpr.ch | IP?  http://www.rawip.org   |


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Bash question

2003-07-01 Thread Colin Watson
On Tue, Jul 01, 2003 at 07:43:28AM -0600, Jamin W. Collins wrote:
 On Tue, Jul 01, 2003 at 02:46:58AM -0500, Stephan Sauerburger wrote:
  So how can one have the for loop separate the elements of the list
  only by newlines (\n), filling the contents of file with the
  whole line, and not separate by spaces, tabs, or other white space?
 
 This has been asked and answered a few times in the past.  There are
 several ways to do it.  Here is one:
 
#!/bin/sh
IFS=$'\n'
 
for FILE in `ls -1`; do
   echo $FILE
done

FYI, Unix filenames are allowed to contain newlines.

-- 
Colin Watson  [EMAIL PROTECTED]


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Bash question

2003-07-01 Thread Alfredo Valles
On Tuesday 01 July 2003 3:18 pm, Colin Watson wrote:

 There's one mistake in the above even before looking at the contents of
 #stuff, namely that you shouldn't be using ls here. Have a look at
 this document written by a friend of mine:

  http://www.greenend.org.uk/rjk/2001/04/shell.html

Thanks for this article, it's cool.

It's true in this case you wouldn't use ls but *.  However, there are other 
times when you want your loop to iterate over the results of other program 
other that ls, and the question remains valid to these cases.

One solution is setting the IFS as I mentioned earlier, but should be other 
solutions maybe more elegant.

Anyway when I want to hear music with mpg123 I use:

find . -iname *mp3 -exec mpg123 '{}' \;

But if you really want to get over this, install music123 and you would have 
all this issues solved for you. You can even play it in random order, make it 
descend dirs, plays wav, ogg and mp3, and it's all from console, not even a 
ncurses menu. Cool !!!  ;-)



-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Bash question

2003-07-01 Thread Colin Watson
On Tue, Jul 01, 2003 at 02:04:35PM +0200, Alfredo Valles wrote:
 On Tuesday 01 July 2003 3:18 pm, Colin Watson wrote:
  There's one mistake in the above even before looking at the contents of
  #stuff, namely that you shouldn't be using ls here. Have a look at
  this document written by a friend of mine:
 
   http://www.greenend.org.uk/rjk/2001/04/shell.html
 
 Thanks for this article, it's cool.
 
 It's true in this case you wouldn't use ls but *.  However, there are other 
 times when you want your loop to iterate over the results of other program 
 other that ls, and the question remains valid to these cases.

That's true. In that case the approach exemplified by 'find -print0 |
xargs -0' is the safest one I know.

Cheers,

-- 
Colin Watson  [EMAIL PROTECTED]


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Bash question

2003-07-01 Thread Alfredo Valles
On Tuesday 01 July 2003 9:46 am, Stephan Sauerburger wrote:
 How do I have it make sure it iterates file-by-file? The following example,
 to play all mp3s in the current directory:

 for file in `ls`
 do
   mpg123 $file
 done

 ...will do just a fine job, so long as none of the file names have any
 spaces in them. If my directory contained:

 Aerosmith - Walk This Way.mp3
 (They Might Be Giants) - Istanbul.mp3
 Pink Floyd - The Wall.mp3


I'm far from beeng an expert but I thing that you need to do is change the 
Internal Field Separator IFS to a new line (the default is space).

It goes:

#Setting the Internal Field Separator to '\n'
IFS='
'

for a in `ls`; do mpg123 $a; done


Good Luck 

   Alfredo

 


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Bash question

2003-07-01 Thread Richard Heycock
ls | while read file
do
cat $bob
done

for loops treat spaces and newlines the same (which is what you are
seeing), the read command reads till the end of the line including
spaces. Note that when you use the environment variable you must quote
it (be sure to use  as opposed to ').

If you want to look at a man page 'man bash' -- it's a builtin.

rgh

On Tue, 2003-07-01 at 17:46, Stephan Sauerburger wrote:
 This is a general shell-scripting question:
 
 In a for loop which runs through all files, as in:
 
 for file in `ls`
 do
   #stuff
 done
 
 How do I have it make sure it iterates file-by-file? The following example, to play 
 all
 mp3s in the current directory:
 
 for file in `ls`
 do
   mpg123 $file
 done
 
 ...will do just a fine job, so long as none of the file names have any
 spaces in them. If my directory contained:
 
 Aerosmith - Walk This Way.mp3
 (They Might Be Giants) - Istanbul.mp3
 Pink Floyd - The Wall.mp3
 
 Then the preceding instructions first try to play Aerosmith, then
 -, then Walk, then This, then Way.mp3, then (They... you get the
 idea. All of which fail, and this could lead to dangerous results if you're
 doing something other than mpg123 to it, like rm, and there were also a
 file simply called Aerosmith.
 
 So how can one have the for loop separate the elements of the list only by
 newlines (\n), filling the contents of file with the whole line,
 and not separate by spaces, tabs, or other white space?
 
 Thx,
 
 -- 
 Stephan
-- 
It is possible to make things of great complexity out of things
 that are very simple. There is no conservation of simplicity
 -- Stephen Wolfram

Richard Heycock [EMAIL PROTECTED]
tel : 0410 646 369
key fingerprint : 909D CBFA C669 AC2F A937  AFA4 661B 9D21 EAAB 4291


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: Bash question

2003-07-01 Thread Kevin McKinley
On Tue, 1 Jul 2003 15:41:56 +0100
Hugh Saunders [EMAIL PROTECTED] wrote:

 On Tue, Jul 01, 2003 at 10:28:32AM -0400, David Z Maze wrote:
  ITYM 'for file in *'...
  ISTR earlier versions...
 flip man! i needed two references to `dict` to read your email.
 Guess i should learn some acronyms!

Hooray for dict IMO. :)

Kevin


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: bash question: reporting a variable named within a variable

2003-04-04 Thread Corey Hickey
Indeed, eval did the trick, exactly what I wanted to do. Thanks to all
who responded, you were most helpful.
-Corey

--
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: bash question: reporting a variable named within a variable

2003-04-04 Thread Rob Sims
On Thursday 03 April 2003 08:01 pm, Bob Proulx wrote:
 Craig Dickson wrote:
  echo $var=$(eval echo \$$var)
 
 That works.  Personally I prefer to eval the entire line.  This way
 you only use one layer of processing rather than the two in the above.
 
   for var in FOO BLAH ; do
 eval echo $var = \$$var;
   done

The following works only in bash, but is smaller and faster:
for var in FOO BLAH ; do
  echo $var = ${!var};
done
--
Rob


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: bash question: reporting a variable named within a variable

2003-04-03 Thread Craig Dickson
Corey Hickey wrote:

 I'm writing a bash script wherein I have a list of variables of which I
 want to return the values. A script representative of what I am trying
 to do would be like this:
 
 
 #!/bin/bash
 
 FOO=bar
 BLAH=blarg
 
 for var in FOO BLAH ; do
   echo $var = $$var #this part is messed up
 done
 #end
 
 
 The script above returns:
 
 FOO = FOO
 BLAH = BLAH
 
 ...but what I want it to return is
 
 FOO = bar
 BLAH = blarg
 
 so obviously I need to change the $$var to something else, but I'm at
 a loss as to what. I've tried various combinations of quotes, dollar
 signs, curly braces, backticks, and pounding myself on the head, but to
 no avail. :)

echo $var=$(eval echo \$$var)

seems to do the trick. You need to escape the first $ to prevent $$
being mistaken for the current process ID variable, and you need eval
to force the variable name to be re-evaluated after the initial
substitution.

Craig


pgp0.pgp
Description: PGP signature


Re: bash question: reporting a variable named within a variable

2003-04-03 Thread Colin Watson
On Thu, Apr 03, 2003 at 01:58:35PM -0800, Corey Hickey wrote:
 This isn't exactly a debian-specific question, but I'm not sure where
 else to turn.
 
 I'm writing a bash script wherein I have a list of variables of which I
 want to return the values. A script representative of what I am trying
 to do would be like this:
 
 
 #!/bin/bash
 
 FOO=bar
 BLAH=blarg
 
 for var in FOO BLAH ; do
   echo $var = $$var #this part is messed up
 done

Try this, which I believe to be the best way:

  echo '$var = ' `eval 'echo $foo'`

Cheers,

-- 
Colin Watson  [EMAIL PROTECTED]


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: bash question: reporting a variable named within a variable

2003-04-03 Thread Bob Proulx
Craig Dickson wrote:
 echo $var=$(eval echo \$$var)

That works.  Personally I prefer to eval the entire line.  This way
you only use one layer of processing rather than the two in the above.

  for var in FOO BLAH ; do
eval echo $var = \$$var;
  done

For those following this scripting discussion, eval scans the line in
a shell evaluation pass one more time.  Therefore in the first pass
the $var becomes FOO, the \$ becomes $, the $var becomes FOO.  So you
then get 'eval echo FOO = $var', which is then evaluated again due to
the eval statement to become, 'echo FOO = bar' and then the echo is
executed with those arguments.

Bob


pgp0.pgp
Description: PGP signature


Re: bash question: reporting a variable named within a variable

2003-04-03 Thread Colin Watson
On Fri, Apr 04, 2003 at 12:34:33AM +0100, Colin Watson wrote:
 On Thu, Apr 03, 2003 at 01:58:35PM -0800, Corey Hickey wrote:
  #!/bin/bash
  
  FOO=bar
  BLAH=blarg
  
  for var in FOO BLAH ; do
  echo $var = $$var #this part is messed up
  done
 
 Try this, which I believe to be the best way:
 
   echo '$var = ' `eval 'echo $foo'`

Make that:

  echo $var =  `eval 'echo $foo'`

-- 
Colin Watson  [EMAIL PROTECTED]


-- 
To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]



Re: BASH question

2002-02-20 Thread Karl E. Jorgensen
On Tue, Feb 19, 2002 at 05:42:35PM +0100, Viktor Rosenfeld wrote:
 Hi,
 
 I have the following bash question.  I've written a script that makes
 sure that I'm online (ISDN dial-on-demand) and then gets mail with
 fetchmail.  He're the code that makes sure I'm connected and prints dots
 while doing so:
 
   # Make sure we're online
   echo -n Connecting to the internet ..
   /bin/bash -c 'while true; do echo -n .; sleep 1s; done' 
   DOTLOOP=$!
   ping -c 1 www.web.de  /dev/null
   kill -9 $DOTLOOP 
   echo  done.
 
 This works fine, but after the fetchmail command runs (not shown there)
 I get the following message:
   
   /home/viktor/bin/getmail: line 16:  3869 Killed
   /bin/bash -c 'while true; do echo -n .; sleep 1s; done'
 
 This, of course, is not surprising, it's normal bash behavior.
 Unfortunately, I don't like it and would like to suppress it.  Any way
 to achieve this?

With kill -9, there is no way the shell can catch it. It's a bit of a
shotgun approach to getting rid of the process (man 7 signal).

However, if you were to settle for the normal kill (= SIGTERM), then you
should be OK:
#!/bin/sh

echo -n Doing something..
(while true; do echo -n .; sleep 1; done) 
DOTLOOP=$!
ping -c 1 www.web.de  /dev/null
kill $DOTLOOP 
echo  done.

HTH
-- 
Karl E. Jørgensen
[EMAIL PROTECTED]
www.karl.jorgensen.com
 Today's fortune:
The University of California Statistics Department; where mean is normal,
and deviation standard.


pgpQltjniiOug.pgp
Description: PGP signature


Re: BASH question

2002-02-20 Thread Viktor Rosenfeld
Karl E. Jorgensen wrote:

 With kill -9, there is no way the shell can catch it. It's a bit of a
 shotgun approach to getting rid of the process (man 7 signal).
 
 However, if you were to settle for the normal kill (= SIGTERM), then you
 should be OK:
 #!/bin/sh
 
 echo -n Doing something..
 (while true; do echo -n .; sleep 1; done) 
 DOTLOOP=$!
 ping -c 1 www.web.de  /dev/null
 kill $DOTLOOP 
 echo  done.

Hmm, not on my system.  The only difference is that the term Killed is
changed to Terminated.  :(

Ciao,
Viktor
-- 
Viktor Rosenfeld
WWW: http://www.informatik.hu-berlin.de/~rosenfel/


pgpW24r6VV0Mc.pgp
Description: PGP signature


Re: bash question.

2002-02-07 Thread Petrov M.I.
Hi All.

 How do you _read_ from the printer, which is an output device?
 Are you trying to get status info back from the printer?  
Yes. I want to get status info. When I do `echo -e ...' then
`cat /dev/lp0' from  command line, this work correctly. When I do
from script this do not work.
 You'd need something more low-level than bash for that.
What?
Thanks.




Re: bash question.

2002-02-07 Thread Ron Johnson
On Thu, 7 Feb 2002 15:49:25 +0200 (EET) Petrov M.I. [EMAIL PROTECTED] wrote:
 Hi All.
 
  How do you _read_ from the printer, which is an output device?
  Are you trying to get status info back from the printer?  
 Yes. I want to get status info. When I do `echo -e ...' then
 `cat /dev/lp0' from  command line, this work correctly. When I do
 from script this do not work.

I wonder if that is because it's in a sub-process?

  You'd need something more low-level than bash for that.

I'd think C...

-- 
++
| Ron Johnson, Jr.Home: [EMAIL PROTECTED]|
| Jefferson, LA  USA  http://ronandheather.dhs.org:81|
||
!  As I like to joke, I may have invented it, but Microsoft |
|   made it popular David Bradley, regarding Ctrl-Alt-Del   |
++



Re: bash question.

2002-02-06 Thread Ron Johnson
On Wed, 6 Feb 2002 20:30:47 +0200 (EET) Petrov M.I. [EMAIL PROTECTED] wrote:
 Hi All.
 I write small script:
  #!/bin/bash
  echo -e ...PJL commands... | cat  /dev/lp0

Try adding a newline:
   echo -e ...PJL commands...\n | cat  /dev/lp0

  cat /dev/lp0

???

 When I try it run I get nothing.
 When I run this script two time (one after the other)
 I get informations.
 I need write to  read from /dev/lp0 in one  the same
 script. How do this do? Any help appreciated.

How do you _read_ from the printer, which is an output device?
Are you trying to get status info back from the printer?  You'd
need something more low-level than bash for that.

-- 
++
| Ron Johnson, Jr.Home: [EMAIL PROTECTED]|
| Jefferson, LA  USA  http://ronandheather.dhs.org:81|
||
! Great Inventors of our time:   |
!Al Gore - Internet |
!Sun Microsystems - Clusters|
++



Re: bash question: identify line number of function call

2001-09-14 Thread Andras BALI
On Fri, Sep 14, 2001 at 05:28:35PM +0200, Martin F Krafft wrote:

 in bash, is it possible to identify the line number of a script, from
 where a function has been called?

You have $LINENO, but it restarts counting from 1 in functions. But if
you invoke the function with $LINENO as argument, the calling line
number will be substituted and passed to the function.

$ cat -n lineno_test.sh
  1  #!/bin/bash
  2
  3  function myfn()
  4  {
  5echo this function has been called from line number #$1
  6  }
  7
  8  myfn $LINENO
  9
 10  exit 0

$ ./lineno_test.sh
this function has been called from line number #8
$

-- 
BALI, Andra's  GPG keyID: 78560E1C
[EMAIL PROTECTED] [EMAIL PROTECTED] [EMAIL PROTECTED]



Re: BASH question

2001-05-12 Thread Karsten M. Self
on Fri, May 11, 2001 at 03:06:07AM -0400, Sunny Dubey ([EMAIL PROTECTED]) wrote:
 Hey,
 
 Anyone know where I might find info about using BASH to create an
 installer for a application?  something that would just ask the person
 various questions, and use that info to create config files and what
 not?

bash can be used for such scripts.  A typical motif is:

echo -e Where do you want to install foo? \c
read wherefoo
case foo in:
bar) qux;;
baz) quux;;
*) default;;
esac

You're going to get more informative results from the list if you can
outline what you want your script to do and pose some specific
questions.

There are also probably tools geared specifically toward this sort of
thing, though I'd probably start with a bash script myself.

The bash man page, the O'Reilly books _Linux in a Nutshell_ and _UNIX
Power Tools_ are also good general references.

You could also look at some standard installer scripts...trying to think
of one off the top of my head.  None are floating up that aren't
attached to some monster applications -- DB/2's installer comes to mind,
but that's a pretty hefty download.. 

Cheers.

-- 
Karsten M. Self kmself@ix.netcom.comhttp://kmself.home.netcom.com/
 What part of Gestalt don't you understand?   There is no K5 cabal
  http://gestalt-system.sourceforge.net/ http://www.kuro5hin.org


pgpylGnVVq7kh.pgp
Description: PGP signature


Re: BASH question

2001-05-12 Thread Henrik Enberg
Karsten M. Self kmself@ix.netcom.com:

 You could also look at some standard installer scripts...trying to think
 of one off the top of my head.  None are floating up that aren't
 attached to some monster applications -- DB/2's installer comes to mind,
 but that's a pretty hefty download.. 

Mayby xmcd..

Henrik
-- 
In Hoc Signo Emacs



Re: bash-question

2000-12-26 Thread Stephan Kulka



 On Mon, Dec 25, 2000 at 10:21:52AM +0100, Stephan Kulka wrote:
  That's quite a newbie question, but I don't know what to do.
  Yesterday I made a new directory for programming, I added this directory
  with export to my PATH. Yesterday everything went fine, but today I always
  get the error command not found. I checked my PATH, it i so.k. and the
  compiled programs work when I type ./foo
  What's wrong??
 
 Today you logged on afresh, and so the path has to be set again.

The strange thing is that I just checked with echo $PATH and I still found
my path I exported yesterday. But when I loooked closer I found out that,
I used a semicolon to separate my directories instead of a colon. Is
there away to change that.



 To free you from the burden to ajust your path (and other prefs.)
 each time you logon, most shells alow you to set those prefs. in a
 *rc (run-command) file. Bash (probably the shell you are using)
 has ~/.bash_profile and ~/.bashrc.  The first gets run for each
 'login' shell, the latter only for non-login shells. (man bash
 for more info; ~/ gets translated to the full path to your home
 directory) 

[snip]

Thanks for the good advice, I will edit my startup files as proposed.

Stephan



Re: bash-question

2000-12-26 Thread Carel Fellinger
On Tue, Dec 26, 2000 at 11:55:13AM +0100, Stephan Kulka wrote:
 
 
 
  On Mon, Dec 25, 2000 at 10:21:52AM +0100, Stephan Kulka wrote:
   That's quite a newbie question, but I don't know what to do.
   Yesterday I made a new directory for programming, I added this directory
   with export to my PATH. Yesterday everything went fine, but today I always
   get the error command not found. I checked my PATH, it i so.k. and the
   compiled programs work when I type ./foo
   What's wrong??
  
  Today you logged on afresh, and so the path has to be set again.
 
 The strange thing is that I just checked with echo $PATH and I still found
 my path I exported yesterday. But when I loooked closer I found out that,
 I used a semicolon to separate my directories instead of a colon. Is
 there away to change that.

If you still find the path you exported yesterday then either A) you
didn't logoff or B) you used some of the bash-startup files to set
the path. In either case the part after the semi-colon is ignored
as the semi-colon is normally used in shell scripts to make the
rest of the line a comment.

In case A it's highly unlikely that it worked yesterday, so probably
you somehow somewhere managed to get your path set at logon.  Places
to look for are /etc/profile, /etc/environment, /etc/bash.bashrc (?),
~/.bashrc, ~/.profile, ~/.bash_login, and ~/.bash_profile. Good luck.

-- 
groetjes, carel



Re: bash-question

2000-12-25 Thread W. Paul Mills
[EMAIL PROTECTED] (Stephan Kulka) writes:


I do not think your PATH is really set. How did you check your
path? Did you echo $PATH to verify?


 That's quite a newbie question, but I don't know what to do.
 Yesterday I made a new directory for programming, I added this directory
 with export to my PATH. Yesterday everything went fine, but today I always
 get the error command not found. I checked my PATH, it i so.k. and the
 compiled programs work when I type ./foo
 What's wrong??
 
 TIA
 
 Stephan
 
 
 -- 
 To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
 with a subject of unsubscribe. Trouble? Contact [EMAIL PROTECTED]
 

-- 
*  For God so loved the world that He gave his only begotten Son,  *
*  that whoever believes in Him should not perish...John 3:16  *
 



Re: bash-question

2000-12-25 Thread Carel Fellinger
On Mon, Dec 25, 2000 at 10:21:52AM +0100, Stephan Kulka wrote:
 That's quite a newbie question, but I don't know what to do.
 Yesterday I made a new directory for programming, I added this directory
 with export to my PATH. Yesterday everything went fine, but today I always
 get the error command not found. I checked my PATH, it i so.k. and the
 compiled programs work when I type ./foo
 What's wrong??

Today you logged on afresh, and so the path has to be set again.
To free you from the burden to ajust your path (and other prefs.)
each time you logon, most shells alow you to set those prefs. in a
*rc (run-command) file. Bash (probably the shell you are using)
has ~/.bash_profile and ~/.bashrc.  The first gets run for each
'login' shell, the latter only for non-login shells. (man bash
for more info; ~/ gets translated to the full path to your home
directory)  So you could have the following in ~./bash_profile:

  # ~/.bash_profile: executed by bash(1) for login shells.

  ### 'source' ~/.bashrc if and only if it exists
  if [ -e ~/.bashrc ]; then
 source ~/.bashrc
  fi

  ### default file protection, no writing for others
  umask 002

  ### make less smarter, uncompressing/untarring etc on the fly
  eval $(lesspipe)
  #eval $(lessfile)

  ### the editor of choice for mutt etc
  export EDITOR='xemacs -nw'


  ### startup an extra Xwindows automatically iff I logon on virtual screen 6
  if [ `tty` = /dev/tty6 ]; then
 exec startx -- :1
  fi


and in your ~/.bashrc you then set the PATH variable like:

  # ~/.bashrc: executed by bash(1) for non-login shells.

  ### you can change your path here, either put your bin upfront
  ### (disadvantage: you now easily overrule genuine system commands)
  #PATH = ~/your-bin:$PATH
  ### or put it at the end
  ### (disadvantage: you now can't overrule system commands:)
  PATH = $PATH:~/your-bin
  ### Normally you're better of using ./your-command

  export LESSCHARSET=latin1

  #no dups in history, skip space prepended lines too
  export HISTIGNORE=: *

-- 
groetjes, carel



Re: Bash question

2000-02-09 Thread Paolo Pedaletti
Ciao Andreas Sliwka,

where or whom should I ask not-so-easy bash questions?

news:comp.unix.shell

Ciao

-- 

Paolo Pedaletti, Como, ITALYa
[EMAIL PROTECTED]


Re: bash question

1999-02-22 Thread E.L. Meijer \(Eric\)
 
 Hi ppl,
 As far as I did not find the answer in bash manual, I hope that
 someone can help me here. Let say I have two bash scripts and I need the 
 parameter which is set in scr2 to be visable in scr1. 
 
 scr1:
   #!/bin/sh
   export LANG=lang1
   echo LANG is $LANG in $0 
   scr2
   echo LANG is $LANG in $0
 scr2:
   #!/bin/sh
   echo LANG is $LANG in $0 
   export LANG=lang2
   echo LANG is $LANG in $0
 
 However the output is :
 LANG is lang1 in ././scr1
 LANG is lang1 in ./scr2 
 LANG is lang2 in ./scr2
 LANG is lang1 in ././scr1
   ^ 
   ... so I have got here the old value of LANG.
 The question is it possible to get the NEW value which is assigned in
 scr2?

Yes.  You need to source the script instead of executing it in a
separate shell.  Then scr2 can actually be viewed as a part of scr1,
but only contained in another file.  You source a script with the `.'
command:

. scr2

The problem with this is that nothing in scr2 is separated from scr1, so
the usefulness of having two scripts is gone.  As an alternative you
could let scr2 print the new value, like

scr2:
   #!/bin/sh
   export LANG=lang2
   echo $LANG

scr1:
   #!/bin/sh
   export LANG=lang1
   echo $LANG
   LANG=`scr1`
   echo $LANG

But this may not be what you want.  The `export' command only works
`downward':  the exported variable is put in the environment of shells
and programs called from the shell where it is used.

HTH,
Eric
   

-- 
 E.L. Meijer ([EMAIL PROTECTED])  | tel. office +31 40 2472189
 Eindhoven Univ. of Technology | tel. lab.   +31 40 2475032
 Lab. for Catalysis and Inorg. Chem. (TAK) | tel. fax+31 40 2455054


Re: bash question

1999-02-22 Thread Eugene Sevinian
Thanks Eric,
I tried sourcing scr2 and it works faster then CALLING scr2.

Eugene.

On Mon, 22 Feb 1999, E.L. Meijer (Eric) wrote:

  
  Hi ppl,
  As far as I did not find the answer in bash manual, I hope that
  someone can help me here. Let say I have two bash scripts and I need the 
  parameter which is set in scr2 to be visable in scr1. 
  
  scr1:
#!/bin/sh
export LANG=lang1
echo LANG is $LANG in $0 
scr2
echo LANG is $LANG in $0
  scr2:
#!/bin/sh
echo LANG is $LANG in $0 
export LANG=lang2
echo LANG is $LANG in $0
  
  However the output is :
  LANG is lang1 in ././scr1
  LANG is lang1 in ./scr2 
  LANG is lang2 in ./scr2
  LANG is lang1 in ././scr1
^ 
... so I have got here the old value of LANG.
  The question is it possible to get the NEW value which is assigned in
  scr2?
 
 Yes.  You need to source the script instead of executing it in a
 separate shell.  Then scr2 can actually be viewed as a part of scr1,
 but only contained in another file.  You source a script with the `.'
 command:
 
 . scr2
 
 The problem with this is that nothing in scr2 is separated from scr1, so
 the usefulness of having two scripts is gone.  As an alternative you
 could let scr2 print the new value, like
 
 scr2:
#!/bin/sh
export LANG=lang2
echo $LANG
 
 scr1:
#!/bin/sh
export LANG=lang1
echo $LANG
LANG=`scr1`
echo $LANG
 
 But this may not be what you want.  The `export' command only works
 `downward':  the exported variable is put in the environment of shells
 and programs called from the shell where it is used.
 
 HTH,
 Eric

 
 -- 
  E.L. Meijer ([EMAIL PROTECTED])  | tel. office +31 40 2472189
  Eindhoven Univ. of Technology | tel. lab.   +31 40 2475032
  Lab. for Catalysis and Inorg. Chem. (TAK) | tel. fax+31 40 2455054
 
 
 -- 
 Unsubscribe?  mail -s unsubscribe [EMAIL PROTECTED]  /dev/null
 

Eugene Sevinian


CRD, YerPhI, 375036, Armenia
URL: http://crdlx5.yerphi.am/
Phone: 374-2-344873


Re: bash question

1999-02-22 Thread E.L. Meijer \(Eric\)
 
 Thanks Eric,
 I tried sourcing scr2 and it works faster then CALLING scr2.
 

This is to be expected: if you call a script, separate shell is started
that runs it.  This takes some time.  If you source a script, the only
overhead is opening and reading an extra file.

Eric

-- 
 E.L. Meijer ([EMAIL PROTECTED])  | tel. office +31 40 2472189
 Eindhoven Univ. of Technology | tel. lab.   +31 40 2475032
 Lab. for Catalysis and Inorg. Chem. (TAK) | tel. fax+31 40 2455054


Re: Bash question/problem.

1998-12-18 Thread Mitch Blevins
Jim Lynch wrote:
 I'v been fighting a bash problem since I first installed bo.  I figured
 it was a bug in bash, but I've now upgraded (partially) to hamm and I've
 still got it.  I'm running 
 
 ii  bash2.01.1-4   The GNU Bourne Again SHell
 
 I'm trying to get my command recall to work in vi mode for root.  When I
 hit the up arrow on the keyboard, it does recall the line, but I can't
 edit it.  The right and left keys don't move, but beep at me.  The hjkl
 keys just insert hjkl into the file.  Thinking it was in an edit mode, I
 tried the ESC key followed by h, j, k or l.  Nope, just beeped at me. 
 I've tried setting my FCEDIT=vi, set -o vi, EDITOR=vi.  Nothing seems to
 work.  I'm at my wits end on this.  If I invoke bash as a normal user (I
 use tcsh normally) the arrow keys don't work, but ESC-k recalls previous
 lines (and ESC-j does as expected) and I can move around on the line
 with h and l.  The i key does inserts, cw changes a word, r and R work
 fine, etc.  So bash knows how, but doesn't work right for root.  
 
 Actually neither work quite the way I want them to.  I'd like for the
 arrow keys to work and the intraline editing.  
 
 Can anyone point me in the right direction?

I had some problems with bash when the shell was invoked thru the symlink
/bin/sh rather than explicitly with /bin/bash.
Maybe that is the problem.
set -o vi  # works for me
echo set editing-mode vi  ~/.inputrc  # is what I use

-Mitch


Re: BASH question

1998-02-16 Thread Daniel Mashao
On Fri, 13 Feb 1998, Fulgham, Brent/SCO wrote:

 Can anyone tell me why I can't generate working Bash scripts?
 
 For example, I want to create a short script called print so that I
 can do some formatted printing:
 
 #!/bin/sh
 # Print -- formatted printer tool to get a 5-space margin and a
 header/footer
 pr -o 5 $1 | lpr
 
There could be many reasons why your scripts do not work. 
1. Does /bin/sh exists?
2. Did you put an extra line at the end of the script?
3. does pr -o 5 filename | lpr work? 
4. Is your path set up right? Do you need to run ./script instead of just
script etc.

Claerly your problem has to do with some misunderstanding of paths etc.

/---/
Daniel J. Mashao
Electrical Engineering[EMAIL PROTECTED]
University of Cape Town http://www.ee.uct.ac.za/~daniel 
Rondebosch, 7700, S. Africa(w) 27+21+650 2816   (h) 27+21+705 1233
/---/


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to
[EMAIL PROTECTED] . 
Trouble?  e-mail to [EMAIL PROTECTED] .


RE: BASH question

1998-02-16 Thread Fulgham, Brent/SCO
For those who are interested, my BASH problems were due to the presence
of some control characters in the script file.  I was using the ae
editor, which in its latest incarnation was inserting a ^M at the end
of each line to signify a carriage return.  Once I switched to vi I
could see the characters, and delete them.  This fixed the scripts.



--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to
[EMAIL PROTECTED] . 
Trouble?  e-mail to [EMAIL PROTECTED] .


Re: BASH question

1998-02-14 Thread Scott McDermott
On Fri, Feb 13, 1998 at 09:50:28AM -0700, Fulgham, Brent/SCO wrote:
 1)  /bin/bash : No such file name
 2)  /bin/bash : Invalid file or directorypr --where part of the error
 message includes the last few characters of each line in the shell
 script.

/bin/sh is not linked to /bin/bash correctly.  This assumes #!/bin/sh
was your magic line in the shell script.

Scott


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to
[EMAIL PROTECTED] . 
Trouble?  e-mail to [EMAIL PROTECTED] .


Re: BASH question

1998-02-13 Thread Ben Pfaff
   Can anyone tell me why I can't generate working Bash scripts?

   Any help would be greatly appreciated.

I suggest that you uuencode one of the non-working scripts and mail it
to the list.  It could be that some funny characters slipped in and
they're confusing bash.


--
TO UNSUBSCRIBE FROM THIS MAILING LIST: e-mail the word unsubscribe to
[EMAIL PROTECTED] . 
Trouble?  e-mail to [EMAIL PROTECTED] .


  1   2   >