Re: Bash Scripting Question

2013-11-07 Thread Chris Davies
Jonathan Dowland  wrote:
> On Sun, Nov 03, 2013 at 09:58:58PM +0100, Erwan David wrote:
>> Maybe you'll need something like expect to handle this.

> I'd second expect, it's probably the best tool for the job in all
> non-trivial cases.

The "empty-expect" package, perhaps?
Chris


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/e2vskaxd2t@news.roaima.co.uk



Re: Bash Scripting Question

2013-11-05 Thread Zenaan Harkness
On 11/4/13, Thomas H. George  wrote:
> The script I am trying to write executes a program that requires a
> keyboard response. I have experimented with redirecting STDIN but haven't
> found the
> correct way to make the response.

To read a value (perhaps half your "problem"):

apt-cache show ...
zenity # gnome
kdialog # kde
xdialog # x generic
expect # Tk (not sure I understand expect)
dialog or whiptail #curses (text)

http://code.google.com/p/yad/ # xenity fork with many improvements

Good luck,
Zenaan


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: 
http://lists.debian.org/caosgnsqrh+2g7issiazssiwhztskydovx459ubygf4frsru...@mail.gmail.com



Re: Bash Scripting Question

2013-11-04 Thread Karl E. Jorgensen
Hi

On Sun, Nov 03, 2013 at 02:35:30PM -0500, Thomas H. George wrote:
> The script I am trying to write executes a program that requires a
> keyboard response. I have experimented with redirecting STDIN but haven't 
> found the
> correct way to make the response.  I found one example that scanned the
> response from apt-get install  for the letter y and fed this back to
> install .  In my case I must respond with a word in answer to the
> programs question.

Well - if you're trying to script a command, have a closer look at the
man-page for the command in question: There may be ways of making the
command non-interactive: Then you don't have to give it any input at
all!

If you are trying to script the "apt-get install" command, check out
the "--yes" option and it's relatives.

Note that apt WILL ask if you're trying to do "crazy" stuff, e.g. like
removing essential packages.  Even the simpler questions are there to
give you a chance not to shoot yourself in the foot: If you script the
answers to them, your (metaphorical) foot is in danger...

> I'm sure this must be elementary but I have read large sections of
> BASH GUIDE FOR BEGINNERS and  AVANCED BASH-SCRIPTING GUIDE without
> finding a solution.  I would appreciate a little help or advice.

:-) Good - that's definitely worth reading.

-- 
Karl E. Jorgensen


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20131104121304.GA10450@hawking



Re: Bash Scripting Question

2013-11-04 Thread Jonathan Dowland
The tool 'yes' can be used to write an infinite stream of strings
(the default being 'y') to standard output, so if your program needed
only a sequence of a fixed string such as 'y', you could do

> yes | your-program

or 

> yes "some-other-string" | your-program

But if your program is not reading strictly from standard input (there
are other ways to get keyboard/interactive input), then…

On Sun, Nov 03, 2013 at 09:58:58PM +0100, Erwan David wrote:
> Maybe you'll need something like expect to handle this.

I'd second expect, it's probably the best tool for the job in all
non-trivial cases.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20131104100536.ga2...@bryant.redmars.org



Re: Bash Scripting Question

2013-11-03 Thread Erwan David
Le 03/11/2013 20:35, Thomas H. George a écrit :
> The script I am trying to write executes a program that requires a
> keyboard response. I have experimented with redirecting STDIN but haven't 
> found the
> correct way to make the response.  I found one example that scanned the
> response from apt-get install  for the letter y and fed this back to
> install .  In my case I must respond with a word in answer to the
> programs question.
>
> I'm sure this must be elementary but I have read large sections of
> BASH GUIDE FOR BEGINNERS and  AVANCED BASH-SCRIPTING GUIDE without
> finding a solution.  I would appreciate a little help or advice.
>
> Tom
>
>

Maybe you'll need something like expect to handle this.


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/5276b912.1080...@rail.eu.org



Re: Bash Scripting Question

2013-11-03 Thread Cousin Stanley

> The script I am trying to write executes a program 
> that requires a keyboard response.
>  

  A varaible can be set to a keyboard response
  using a  read  prompt  

read -e -p "What do you need ?" xVariable

echo $xVariable


-- 
Stanley C. Kitching
Human Being
Phoenix, Arizona


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/l56bqj$62c$1...@dont-email.me



Re: bash scripting question

2010-03-29 Thread Karl Vogel
Here's something I modified as part of a benchmark script called "fdtree".

-- 
Karl Vogel  I don't speak for the USAF or my company
Dijkstra probably hates me. --Linus Torvalds, in kernel/sched.c

#!/bin/bash
# How to use xdate/xtime/persec:
#
#  START=$(date "+%s")
#  count=10
#  xdate
#  tin=$(xtime)
#
#  # do something time-consuming $count times...
#  tout=$(xtime)
#  set $(persec $tin $tout $count); ttot=$1; results=$2
#  xdate
#  echo "TIME IN, OUT, TOTAL = "$tin, $tout, $ttot
#  echo -e "\tWork per second = " $results

PATH=/usr/local/bin:/bin:/usr/bin
export PATH

function xdate
# Display the date in this form: Thu, 10 Sep 2009 21:22:06.494
{
set $(date "+%a, %d %b %Y %T %N")
ms=$(echo $6 | cut -c1-3)
echo "$1 $2 $3 $4 $5.$ms"
}

function xtime
# Display elapsed runtime to the millisecond.
{
set $(date "+%s %N")
sec=$(($1 - $START))
ms=$(echo $2 | cut -c1-3)
echo "$sec.$ms"
}

function persec
# args: start-second, finish-second, count-things
# returns elapsed time and things that happened per second
# to the millisecond.
{
start=$1
finish=$2
count=$3

if test "$finish" = "$start"; then
echo "0 0"
else
echo $(echo "scale=3; $finish-$start;
$count/($finish-$start)" | bc)
fi
}

function dbg
# debugging prints
{
test $DEBUG -gt 0 && echo -e "$@"
}

tmp=/tmp/t1$$
tmp2=/tmp/t2$$

xdate
START=$(date "+%s")
tin=$(xtime)
echo

for k in 1 2 3 4 5 6 7 8 9 10
do
# Read a short amount of random data.
dd if=/dev/random of=$tmp2 bs=1k count=1 2> /dev/null

# Duplicate it a bunch of times.
cat $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 > $tmp
cat $tmp  $tmp  $tmp  $tmp  $tmp  $tmp  $tmp  $tmp  > $tmp2
cat $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 > $tmp
cat $tmp  $tmp  $tmp  $tmp  $tmp  $tmp  $tmp  $tmp  > $tmp2
cat $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 $tmp2 > $tmp
rm $tmp2

# Generate a hash.
md5sum $tmp
ls -l $tmp
rm $tmp
done

echo
count=10
tout=$(xtime)
set $(persec $tin $tout $count); ttot=$1; results=$2
xdate

echo "TIME IN, OUT, TOTAL = "$tin, $tout, $ttot
echo -e "\tWork per second = " $results
exit 0


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100330012125.34bebb...@bsd118.wpafb.af.mil



Re: bash scripting question

2010-03-29 Thread Ron Johnson

On 2010-03-29 16:35, Mike McClain wrote:
[snip]


Thanks a lot. Though my error was pointed out as a typo and corrected
a while back your solution using " date '+%s' " is much more elegant
than what I had done.


If you want more (possibly too much) precision:
$ date +'%s.%N'

--
"History does not long entrust the care of freedom to the weak
or the timid."  Dwight Eisenhower


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

Archive: http://lists.debian.org/4bb14146.1060...@cox.net



Re: bash scripting question

2010-03-29 Thread Mike McClain
Hi Josep,

On Mon, Mar 29, 2010 at 02:28:20PM +0200, Josep M. wrote:
> 
> I found these somewhere time ago. check if is what You need:
> 
 

Thanks a lot. Though my error was pointed out as a typo and corrected
a while back your solution using " date '+%s' " is much more elegant
than what I had done.

Mike

PS: Since I posted to and read the list you needn't email me direct.
MM
-- 
Satisfied user of Linux since 1997.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100329213536.gb29...@playground.mcclains.net



Re: bash scripting question

2010-03-29 Thread Josep M.
Hello.

I found these somewhere time ago. check if is what You need:





function timer()
{
if [[ $# -eq 0 ]]; then
echo $(date '+%s')
else
local  stime=$1
etime=$(date '+%s')

if [[ -z "$stime" ]]; then stime=$etime; fi

dt=$((etime - stime))
ds=$((dt % 60))
dm=$(((dt / 60) % 60))
dh=$((dt / 3600))
printf '%d:%02d:%02d' $dh $dm $ds
fi
}

 
This is before the command

t=$(timer)

and this is after the command

printf 'Elapsed time: %s\n' $(timer $t)



example

t=$(timer)

copy /dev/null /dev/zero

printf 'Elapsed time: %s\n' $(timer $t)



Greetings
Josep

El vie, 19-03-2010 a las 10:19 -0700, Mike McClain escribió:
> I've written a function to print elapsed time similar to /usr/bin/time
> but can be called at the beginning and end of a script from within
> the script. Occasionally I get an error: '8-08: value too great for base'
> It's caused by the difference in these 2 command strings but I can't for 
> the life of me see what's going on.
> 
> now='09:07:16'; startHr=${now%%:*}; startHR=${startHr#*0}; echo $startHr; 
> 09
> 
> str=09; str=${str#*0}; echo $str; 
> 9
> 
> Thanks,
> Mike
> -- 
> Satisfied user of Linux since 1997.
> O< ascii ribbon campaign - stop html mail - www.asciiribbon.org
> 
> 



-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/1269865700.29265.2.ca...@mail.navegants.net



Re: bash scripting question

2010-03-19 Thread Chris Jackson

Paul E Condon wrote:


Try:

bgn=$(date +%s)
sleep 7
end=$(date +%s)
echo "elapsed seconds = " $(( end - bgn ))



You might also want to experiment with:

ps h -o etime $$

as long as you're happy with it only running under gnu. Prints the 
elapsed time for the shell.


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

Archive: http://lists.debian.org/4ba3dae2.7080...@shadowcat.co.uk



Re: bash scripting question

2010-03-19 Thread Paul E Condon
On 20100319_101928, Mike McClain wrote:
> I've written a function to print elapsed time similar to /usr/bin/time
> but can be called at the beginning and end of a script from within
> the script. Occasionally I get an error: '8-08: value too great for base'
> It's caused by the difference in these 2 command strings but I can't for 
> the life of me see what's going on.
> 
> now='09:07:16'; startHr=${now%%:*}; startHR=${startHr#*0}; echo $startHr; 
> 09
> 
> str=09; str=${str#*0}; echo $str; 
> 9

Try:

bgn=$(date +%s)
sleep 7
end=$(date +%s)
echo "elapsed seconds = " $(( end - bgn ))

Play with values other than '7'.

To actually use in a script, replace the sleep command by whatever you
want to measure the elapsed time for. 

Expressing elapsed time as HH:MM:SS requires a little more work. To 
write that script, use / for divide operator and % for remainder operator,
like in C.

-- 
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
Archive: http://lists.debian.org/20100319194539.gh7...@big.lan.gnu



Re: bash scripting question

2010-03-19 Thread Mike McClain
On Fri, Mar 19, 2010 at 06:45:15PM +0100, Sven Joachim wrote:
> On 2010-03-19 18:19 +0100, Mike McClain wrote:
> 
> > I've written a function to print elapsed time similar to /usr/bin/time
> > but can be called at the beginning and end of a script from within
> > the script. Occasionally I get an error: '8-08: value too great for base'
> > It's caused by the difference in these 2 command strings but I can't for 
> > the life of me see what's going on.
> 
> Apparently bash is treating the number as octal because it starts with a
> leading 0.
> 
> Sven

In one case but not the other? 
What makes them treated differently?
Mike
-- 
Satisfied user of Linux since 1997.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100319190719.ga32...@playground.mcclains.net



Re: bash scripting question

2010-03-19 Thread Mike McClain
On Fri, Mar 19, 2010 at 10:19:28AM -0700, Mike McClain wrote:


typo right herevv 
> now='09:07:16'; startHr=${now%%:*}; startHR=${startHr#*0}; echo $startHr; 

Apologies for troubling all.
Mike (with egg on face)
-- 
Satisfied user of Linux since 1997.
O< ascii ribbon campaign - stop html mail - www.asciiribbon.org


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/20100319191837.ga32...@playground.mcclains.net



Re: bash scripting question

2010-03-19 Thread Wayne

Mike McClain wrote:

I've written a function to print elapsed time similar to /usr/bin/time
but can be called at the beginning and end of a script from within
the script. Occasionally I get an error: '8-08: value too great for base'
It's caused by the difference in these 2 command strings but I can't for 
the life of me see what's going on.


now='09:07:16'; startHr=${now%%:*}; startHR=${startHr#*0}; echo $startHr; 
09


str=09; str=${str#*0}; echo $str; 



I do it like this
# Set date format
ISO_8601='%Y-%m-%d %H:%M:%S%z'


aptitude safe-upgrade
date "+System Upgrade Completed at: $ISO_8601">>/root/Admin/last-upgrade

the result is

Update started at  : 2010-03-19 08:50:53-0400
Update completed at: 2010-03-19 08:52:19-0400
Upgrade Download started at : 2010-03-19 08:52:19-0400
Download Completed at  : 2010-03-19 09:01:52-0400
System Upgrade Completed at: 2010-03-19 09:05:39-0400

HTH

Wayne


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

Archive: http://lists.debian.org/4ba3bd88.4020...@gmail.com



Re: bash scripting question

2010-03-19 Thread Chris Jackson

Mike McClain wrote:


I've written a function to print elapsed time similar to /usr/bin/time
but can be called at the beginning and end of a script from within
the script. Occasionally I get an error: '8-08: value too great for base'
It's caused by the difference in these 2 command strings but I can't for 
the life of me see what's going on.


now='09:07:16'; startHr=${now%%:*}; startHR=${startHr#*0}; echo $startHr; 
09


str=09; str=${str#*0}; echo $str; 
9



Did you mean to echo $startHR - capital 'R' - in the first one? That is 
'9' as you are expecting ;)


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

Archive: http://lists.debian.org/4ba3bb55.50...@shadowcat.co.uk



Re: bash scripting question

2010-03-19 Thread S Scharf
On Fri, Mar 19, 2010 at 1:19 PM, Mike McClain  wrote:

> I've written a function to print elapsed time similar to /usr/bin/time
> but can be called at the beginning and end of a script from within
> the script. Occasionally I get an error: '8-08: value too great for base'
> It's caused by the difference in these 2 command strings but I can't for
> the life of me see what's going on.
>
> now='09:07:16'; startHr=${now%%:*}; startHR=${startHr#*0}; echo $startHr;
> 09
>
> str=09; str=${str#*0}; echo $str;
> 9
>
> Thanks,
> Mike
>
>
Did you wand to echo startHR and not startHr in the first expression?

Stuart


Re: bash scripting question

2010-03-19 Thread Sven Joachim
On 2010-03-19 18:19 +0100, Mike McClain wrote:

> I've written a function to print elapsed time similar to /usr/bin/time
> but can be called at the beginning and end of a script from within
> the script. Occasionally I get an error: '8-08: value too great for base'
> It's caused by the difference in these 2 command strings but I can't for 
> the life of me see what's going on.

Apparently bash is treating the number as octal because it starts with a
leading 0.

Sven


-- 
To UNSUBSCRIBE, email to debian-user-requ...@lists.debian.org 
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: http://lists.debian.org/87bpekp5n8@turtle.gmx.de



Re: bash scripting question

2007-05-17 Thread Bob McGowan

Tyler Smith wrote:

On 2007-05-17, Bob McGowan <[EMAIL PROTECTED]> wrote:
Some general comments, mostly aimed at making your code cleaner without 
changing what it does.


First, both 'echo' and 'printf' put their results on standard out.  Your 
call of 'printf' is inside command substitution, so its STDOUT becomes 

--snipped stuff--


Oh, great, thanks. I added the echo to stop getting the complaint
about unknown command, but this is better.


So, cut and pasted from a bash shell:

$ lab_num=41
$ lab_let=$(printf "\x$lab_num")
$ echo $lab_let
A
$ ((lab_num++))
$ lab_let=$(printf "\x$lab_num")
$ echo $lab_let
B


Much improved!

This would need two loops, the outer to increment the 'tens' digit, the 
inner to increment the 'ones' digit, but it would do the trick.  For 
example:


x=(0 1 2 3 4 5 6 7 8 9 A B C D E F)



I knew there was an array form in bash, but I couldn't find it. I'm
working from the O'Reilly book classic shell scripting, and the only
reference to arrays is in relation to awk scripts. This is a big help.

Thanks alot!

Tyler




You're welcome ;)

Bob


smime.p7s
Description: S/MIME Cryptographic Signature


Re: bash scripting question

2007-05-16 Thread Alex Samad
On Thu, May 17, 2007 at 03:40:15AM +, Tyler Smith wrote:
> On 2007-05-17, Bob McGowan <[EMAIL PROTECTED]> wrote:
> >
> > Some general comments, mostly aimed at making your code cleaner without 
> > changing what it does.
> >
> > First, both 'echo' and 'printf' put their results on standard out.  Your 
> > call of 'printf' is inside command substitution, so its STDOUT becomes 
> > the command line for 'echo' which just prints to its STDOUT.  Why the 
> > double print out?  Just do:
> >
> > lab_let=$(printf "\\x$(echo $lab_num)")
> >
> > Next, the 'echo $lab_num' is not needed, $lab_num can stand alone:
> >
> > lab_let=$(printf "\\x$lab_num")

another thing to remember is you can enclose your variable names in {} so you 
could do something like 

lab_let=$(printf "\\x${lab_num}Moretext")

> >
> > And, the double quotes escape things, too, so the double backslash is 
> > not needed:
> >
> > lab_let=$(printf "\x$lab_num")
> >
> 
> Thank you for this! I started out with something a little more
> complicated, without the variable, trying to insert the hex character
> directly into another command. And my testing required that I use a
> form that would print something to the command line. I got very worked
> up trying to sort out the syntax, and obviously over-did it.
> 
> 
> > Then, the line where you increment lab_num can also be simpler.  In bash 
> > the $((...)) alone on a line will replace itself with the result 
> > (command substitution, again).  But, leave off the leading $ sign, and 
> > it just does the increment:
> >
> > ((lab_num++))
> 
> Oh, great, thanks. I added the echo to stop getting the complaint
> about unknown command, but this is better.
> 
> >
> > So, cut and pasted from a bash shell:
> >
> > $ lab_num=41
> > $ lab_let=$(printf "\x$lab_num")
> > $ echo $lab_let
> > A
> > $ ((lab_num++))
> > $ lab_let=$(printf "\x$lab_num")
> > $ echo $lab_let
> > B
> 
> Much improved!
> 
> >
> > This would need two loops, the outer to increment the 'tens' digit, the 
> > inner to increment the 'ones' digit, but it would do the trick.  For 
> > example:
> >
> > x=(0 1 2 3 4 5 6 7 8 9 A B C D E F)
> >
> 
> I knew there was an array form in bash, but I couldn't find it. I'm
> working from the O'Reilly book classic shell scripting, and the only
> reference to arrays is in relation to awk scripts. This is a big help.
> 
> Thanks alot!
> 
> Tyler
> 
> 
> -- 
> To UNSUBSCRIBE, email to [EMAIL PROTECTED] 
> with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
> 
> 


signature.asc
Description: Digital signature


Re: bash scripting question

2007-05-16 Thread Tyler Smith
On 2007-05-17, Bob McGowan <[EMAIL PROTECTED]> wrote:
>
> Some general comments, mostly aimed at making your code cleaner without 
> changing what it does.
>
> First, both 'echo' and 'printf' put their results on standard out.  Your 
> call of 'printf' is inside command substitution, so its STDOUT becomes 
> the command line for 'echo' which just prints to its STDOUT.  Why the 
> double print out?  Just do:
>
> lab_let=$(printf "\\x$(echo $lab_num)")
>
> Next, the 'echo $lab_num' is not needed, $lab_num can stand alone:
>
> lab_let=$(printf "\\x$lab_num")
>
> And, the double quotes escape things, too, so the double backslash is 
> not needed:
>
> lab_let=$(printf "\x$lab_num")
>

Thank you for this! I started out with something a little more
complicated, without the variable, trying to insert the hex character
directly into another command. And my testing required that I use a
form that would print something to the command line. I got very worked
up trying to sort out the syntax, and obviously over-did it.


> Then, the line where you increment lab_num can also be simpler.  In bash 
> the $((...)) alone on a line will replace itself with the result 
> (command substitution, again).  But, leave off the leading $ sign, and 
> it just does the increment:
>
> ((lab_num++))

Oh, great, thanks. I added the echo to stop getting the complaint
about unknown command, but this is better.

>
> So, cut and pasted from a bash shell:
>
> $ lab_num=41
> $ lab_let=$(printf "\x$lab_num")
> $ echo $lab_let
> A
> $ ((lab_num++))
> $ lab_let=$(printf "\x$lab_num")
> $ echo $lab_let
> B

Much improved!

>
> This would need two loops, the outer to increment the 'tens' digit, the 
> inner to increment the 'ones' digit, but it would do the trick.  For 
> example:
>
> x=(0 1 2 3 4 5 6 7 8 9 A B C D E F)
>

I knew there was an array form in bash, but I couldn't find it. I'm
working from the O'Reilly book classic shell scripting, and the only
reference to arrays is in relation to awk scripts. This is a big help.

Thanks alot!

Tyler


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



Re: bash scripting question

2007-05-16 Thread Bob McGowan

Tyler Smith wrote:

Hi,

I've got a question about a short bash script I wrote. I need it to

--snipped--


#!/bin/bash

lab_num=41

for map_name in aest_90 bush_90 carol_90 comp_90 \
hirs_90 roan_90 swan_90 vir_90 ; 


  do

  lab_let=$(echo -n $(printf "\\x$(echo $lab_num)"))

  echo "
  $lab_let
  $map_name
  ${map_name}.ps" ;

  echo $((lab_num++)) > /dev/null ;

  done

--snipped--

Some general comments, mostly aimed at making your code cleaner without 
changing what it does.


First, both 'echo' and 'printf' put their results on standard out.  Your 
call of 'printf' is inside command substitution, so its STDOUT becomes 
the command line for 'echo' which just prints to its STDOUT.  Why the 
double print out?  Just do:


lab_let=$(printf "\\x$(echo $lab_num)")

Next, the 'echo $lab_num' is not needed, $lab_num can stand alone:

lab_let=$(printf "\\x$lab_num")

And, the double quotes escape things, too, so the double backslash is 
not needed:


lab_let=$(printf "\x$lab_num")

Then, the line where you increment lab_num can also be simpler.  In bash 
the $((...)) alone on a line will replace itself with the result 
(command substitution, again).  But, leave off the leading $ sign, and 
it just does the increment:


((lab_num++))

So, cut and pasted from a bash shell:

$ lab_num=41
$ lab_let=$(printf "\x$lab_num")
$ echo $lab_let
A
$ ((lab_num++))
$ lab_let=$(printf "\x$lab_num")
$ echo $lab_let
B




Thanks,

Tyler




Since you're using bash, you may also find it convenient to put your hex 
digits into an array, which you can then subscript into with decimal 
numbers, to build the hex values needed to print other characters.


This would need two loops, the outer to increment the 'tens' digit, the 
inner to increment the 'ones' digit, but it would do the trick.  For 
example:


x=(0 1 2 3 4 5 6 7 8 9 A B C D E F)

tens=0
digits=0

while [ $tens -lt 3 ]
do
  while [ $digits -lt 16 ]
  do
echo ${x[$tens]}${x[$digits]}
((digits++))
  done
  digits=0
  ((tens++))
done

The result is:

00
01
02
.
.
.
2D
2E
2F

Change the 'tens' and 'digits' as needed to get the right starting value.

Bob


smime.p7s
Description: S/MIME Cryptographic Signature


Re: bash scripting question

2007-05-16 Thread Tyler Smith
On 2007-05-16, Karl E. Jorgensen <[EMAIL PROTECTED]> wrote:
>> This was the only way I could figure out to loop from A to H. But
>> since it works on hex escape codes, it won't work past 9. Is there a
>> cleaner, more general way to do this?
>
> I think there is:
>
> #!/bin/bash
>
> ( cat < A aest_90
> B bush_90
> C carol_90
> D comp_90
> E hirs_90
> F roan_90
> G swan_90
> H vir_90
> !
> ) | while read letter name
> do
> printf '%s\n%s\n%s.ps\n\n' "$letter" "$name" "$name"
> done
>
> Hope this helps
>

Very much! That's perfect.

Cheers,

Tyler


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



Re: bash scripting question

2007-05-16 Thread Karl E. Jorgensen
On Wed, May 16, 2007 at 08:46:37PM +, Tyler Smith wrote:
> Hi,
> 
> I've got a question about a short bash script I wrote. I need it to
> loop over a number of names, and pass a command to grass that includes
> two variations of those names. That was easy. Harder was getting
> getting a letter included in each iteration, starting with A for the
> first one and going up by one each iteration. What I came up with,
> with extra bits snipped, is:
> 
> #!/bin/bash
> 
> lab_num=41
> 
> for map_name in aest_90 bush_90 carol_90 comp_90 \
> hirs_90 roan_90 swan_90 vir_90 ; 
> 
>   do
> 
>   lab_let=$(echo -n $(printf "\\x$(echo $lab_num)"))
> 
>   echo "
>   $lab_let
>   $map_name
>   ${map_name}.ps" ;
> 
>   echo $((lab_num++)) > /dev/null ;
> 
>   done
> 
> The multi-line echo is passing instructions to a GRASS command, and in
> the full script it works fine. This example runs fine without grass as
> a demonstration. What I'm wondering about is the line:
> 
>   lab_let=$(echo -n $(printf "\\x$(echo $lab_num)"))
> 
> This was the only way I could figure out to loop from A to H. But
> since it works on hex escape codes, it won't work past 9. Is there a
> cleaner, more general way to do this?

I think there is:

#!/bin/bash

( cat 

Re: bash scripting q

2006-09-29 Thread Kevin Mark
On Fri, Sep 29, 2006 at 08:02:38AM -0500, Hugo Vanwoerkom wrote:
> Kevin Mark wrote:
> >On Wed, Sep 27, 2006 at 09:22:05PM -0500, Ron Johnson wrote:
> >>how about
> >>  b=`$a`
> >>  echo $b
> >
> >or 
> >echo $($a)
> 
> 
> Bingo!!! Thanks!
> Is that in the Advanced Bash-Scripting Guide?
> H
> 
Hi Hugo,
A is used for assignment of A
$A is to show the value of A
$($A) is to evaluate the command string that $A returns
`$A` is the old way and I think more compatible
cheers,
Kev
-- 
|  .''`.  == Debian GNU/Linux == |   my web site:   |
| : :' :  The  Universal | debian.home.pipeline.com |
| `. `'  Operating System| go to counter.li.org and |
|   `-http://www.debian.org/ |be counted! #238656   |
| my keysever: pgp.mit.edu   | my NPO: cfsg.org |


signature.asc
Description: Digital signature


Re: bash scripting q

2006-09-29 Thread Hugo Vanwoerkom

Hugo Vanwoerkom wrote:

Hi,

On my way to elapsed time in a bash script, I created the do_chrono 
command. It pumps the elapsed time to stdout.


So if I do:

a=do_chrono

and then:

$a

I get: 0:3:19.

Problem: I can't use that $a anywhere, e.g. if I say:

echo $a

I would expect to see 0:3:19 again, but I don't, it says

do_chrono


How do I use that $a in command parameters, like logger?



So this is the way it works now:

#!/bin/bash
a=do_chrono # elap to stdout
$($a) &> /dev/null  # Suppress output 1st call clears the chronometer(1)
sleep 1
logger -t do_hibernate_prep =before sleep 4 $($a) # elap since (1)(2)
sleep 4
logger -t do_hibernate_prep =after sleep 4 $($a) # elap since (2)
exit 0

Produces:

Sep 29 09:21:27 debian do_hibernate_prep: =do_hibernate_prep before 
sleep 4 0:0:1.30
Sep 29 09:21:31 debian do_hibernate_prep: =do_hibernate_prep after sleep 
4 0:0:4.30


There probably are better ways of doing it.
Thanks for the answers, couldn't find that in the guide...
H






















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




Re: bash scripting q

2006-09-29 Thread Hugo Vanwoerkom

Kevin Mark wrote:

On Wed, Sep 27, 2006 at 09:22:05PM -0500, Ron Johnson wrote:

how about
  b=`$a`
  echo $b


or 
echo $($a)



Bingo!!! Thanks!
Is that in the Advanced Bash-Scripting Guide?
H




echo `$a`




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




Re: bash scripting q

2006-09-29 Thread Hugo Vanwoerkom

Atle Veka wrote:

In your example you are saying that $a is the function 'do_chrono', so
when you run $a, it runs the function and prints out the result. As
another poster indicated, you need to do it slightly differently:

# execute and store result in $a
a=$( do_chrono )

# print
echo $a




Yup, that too!

Thanks!
H


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




Re: bash scripting q

2006-09-29 Thread Hugo Vanwoerkom

Ron Johnson wrote:

-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 09/27/06 18:51, Hugo Vanwoerkom wrote:

Hi,

On my way to elapsed time in a bash script, I created the do_chrono
command. It pumps the elapsed time to stdout.

So if I do:

a=do_chrono

and then:

$a

I get: 0:3:19.

Problem: I can't use that $a anywhere, e.g. if I say:

echo $a

I would expect to see 0:3:19 again, but I don't, it says

do_chrono


How do I use that $a in command parameters, like logger?


how about
  b=`$a`
  echo $b




$a























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




Re: bash scripting q

2006-09-28 Thread Kevin Mark
On Wed, Sep 27, 2006 at 09:22:05PM -0500, Ron Johnson wrote:
> 
> how about
>   b=`$a`
>   echo $b

or 
echo $($a)
echo `$a`

-- 
|  .''`.  == Debian GNU/Linux == |   my web site:   |
| : :' :  The  Universal | debian.home.pipeline.com |
| `. `'  Operating System| go to counter.li.org and |
|   `-http://www.debian.org/ |be counted! #238656   |
| my keysever: pgp.mit.edu   | my NPO: cfsg.org |


signature.asc
Description: Digital signature


Re: bash scripting q

2006-09-27 Thread Atle Veka
In your example you are saying that $a is the function 'do_chrono', so
when you run $a, it runs the function and prints out the result. As
another poster indicated, you need to do it slightly differently:

# execute and store result in $a
a=$( do_chrono )

# print
echo $a


Atle
-
Flying Crocodile Inc, Unix Systems Administrator

On Wed, 27 Sep 2006, Hugo Vanwoerkom wrote:

> Hi,
>
> On my way to elapsed time in a bash script, I created the do_chrono
> command. It pumps the elapsed time to stdout.
>
> So if I do:
>
> a=do_chrono
>
> and then:
>
> $a
>
> I get: 0:3:19.
>
> Problem: I can't use that $a anywhere, e.g. if I say:
>
> echo $a
>
> I would expect to see 0:3:19 again, but I don't, it says
>
> do_chrono
>
>
> How do I use that $a in command parameters, like logger?
>
> Thanks!
>
> H
>


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



Re: bash scripting q

2006-09-27 Thread Ron Johnson
-BEGIN PGP SIGNED MESSAGE-
Hash: SHA1

On 09/27/06 18:51, Hugo Vanwoerkom wrote:
> Hi,
> 
> On my way to elapsed time in a bash script, I created the do_chrono
> command. It pumps the elapsed time to stdout.
> 
> So if I do:
> 
> a=do_chrono
> 
> and then:
> 
> $a
> 
> I get: 0:3:19.
> 
> Problem: I can't use that $a anywhere, e.g. if I say:
> 
> echo $a
> 
> I would expect to see 0:3:19 again, but I don't, it says
> 
> do_chrono
> 
> 
> How do I use that $a in command parameters, like logger?

how about
  b=`$a`
  echo $b

- --
Ron Johnson, Jr.
Jefferson LA  USA

Is "common sense" really valid?
For example, it is "common sense" to white-power racists that
whites are superior to blacks, and that those with brown skins
are mud people.
However, that "common sense" is obviously wrong.
-BEGIN PGP SIGNATURE-
Version: GnuPG v1.4.5 (GNU/Linux)

iD8DBQFFGzHNS9HxQb37XmcRAqCmAKCkkUWs5cpymsUNFJQD66TqPmFhcgCeNsB1
Z1HAzJJ/M9T/rXAxgl0vOYQ=
=YPXa
-END PGP SIGNATURE-


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



Re: BASH Scripting Question

2005-11-25 Thread David Kirchner
On 11/25/05, Metrics <[EMAIL PROTECTED]> wrote:
> Hi all,
>
> Can someone explain to me the following behaviour? I have this script
>
> #!/bin/sh
>
> LISTS=('debian-user' 'security-basics' 'hostap' 'pen-test' 'ntbugtraq' 
> 'ion-general' 'vim' 'madwifi');
> LIST_COUNT=${#LISTS}
> echo $LIST_COUNT
>
> for ((i=0;i<$LIST_COUNT-1;i++)); do
> echo /home/bhillis/Maildir/.${LISTS[${i}]}/
> done

11 is the length of the string 'debian-user'.

LIST_COUNT=$((${#LISTS[*]}+1))

will give you the right number.



Re: Bash scripting

2003-03-10 Thread Ron Johnson
On Mon, 2003-03-10 at 01:02, Jeff Elkins wrote:
> Jeff Elkins <[EMAIL PROTECTED]> writes:
> > ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e
> > s/arm.*/arm/ -e s/sa110/arm/
> >
> > I'm working on polishing my meagre shell scripting skills and would
> > appreciate some feedback on the line above, quoted from the kernel
> > Makefile.
> 
> Thanks for the replies folks!

Note that if you just want to find out if "this OR that" is on a line
or in a stream, some examples:
  dmesg | egrep "port|connection"
  egrep -n "port|connection" /var/log/dmesg

-- 
+---+
| Ron Johnson, Jr.mailto:[EMAIL PROTECTED]  |
| Jefferson, LA  USA  http://members.cox.net/ron.l.johnson  |
|   |
| Spit in one hand, and wish for peace in the other.|
| Guess which is more effective...  |
+---+


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



Re: Bash scripting

2003-03-09 Thread Jeff Elkins
Jeff Elkins <[EMAIL PROTECTED]> writes:
> ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e
> s/arm.*/arm/ -e s/sa110/arm/
>
> I'm working on polishing my meagre shell scripting skills and would
> appreciate some feedback on the line above, quoted from the kernel
> Makefile.

Thanks for the replies folks!



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



Re: Bash scripting

2003-03-09 Thread Jereme Corrado
Hi Jeff,

Jeff Elkins <[EMAIL PROTECTED]> writes:
> ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e 
> s/arm.*/arm/ -e s/sa110/arm/
> 
> I'm working on polishing my meagre shell scripting skills and would
> appreciate some feedback on the line above, quoted from the kernel Makefile.

[...]

> 2. As far as comparisons go, if I wanted to determine if a string contained
> ".xyz" or ".abc" would that be a variant of the fragment above?

The fragment above is a series of sed statements used to normalize the
machines architecture.  The `.' is a regular expression that matches
any single character, s/// is the substation operator, so

sed -e 's/i.86/i386/'

would match "i386", "i486", "i586" and replace it with "i386", that is
what I meant by "normalize".  As it were, it would match "i""386".  I added the quotes around the sed expression
in case you wanted to try it at the CL.



-jereme

-- 
+--+
Jereme Corrado <[EMAIL PROTECTED]>
System Administrator
Restorative Management Corp.

gpg: 1024D/9C39E1F0


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



Re: Bash scripting

2003-03-09 Thread Bob Proulx
Jeff Elkins wrote:
> ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e 
> s/arm.*/arm/ -e s/sa110/arm/
> 
> I'm working on polishing my meagre shell scripting skills and would
> appreciate some feedback on the line above, quoted from the kernel Makefile.

Ew, that line seems to be so specific.  You might want to check out
config.guess from the gnu archive or any gnu program that uses it.  It
is a *VERY* long script to more completely do the above.  In general,
avoid needing the architecture like that.  But sometimes you can't
avoid it.

> 1. How would you use this in a straight bash script so it returned a value
> containing the boxes architecture?

  uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/ -e s/sa110/arm/

But really just uname -m is fine.

  case "$(uname -m)" in
i?86) echo Hello x86, pleased to meet you. ;;
ia64) echo Hello ia64, pleased to meet you. ;;
  esac

But there are lots of machine variants.  Trying to enumerate them all
is a path of frustration.

> 2. As far as comparisons go, if I wanted to determine if a string contained
> ".xyz" or ".abc" would that be a variant of the fragment above?

Contained?  Or ending in?  Contained:

  string="dog.xyz"
  case "$string" in
*.xyz*) echo Hello .xyz, pleased to meet you. ;;
*.abc*) echo Hello .abc, pleased to meet you. ;;
  esac

Ending in:

  string="dog.xyz"
  case "$string" in
*.xyz) echo Hello .xyz, pleased to meet you. ;;
*.abc) echo Hello .abc, pleased to meet you. ;;
  esac

Bob


pgp0.pgp
Description: PGP signature


Re: Bash scripting

2003-03-09 Thread Bob Proulx
David Z Maze wrote:
> Two somewhat common ways:
> 
>   uname -m | grep i.86 > /dev/null && echo x86

My I suggest using 'grep -q' to save the need to redirect?

>   case `uname -m` in
> i?86) echo x86 ;;
>   esac

I prefer the case statement approach.

Bob


pgp0.pgp
Description: PGP signature


Re: Bash scripting

2003-03-09 Thread David Z Maze
Jeff Elkins <[EMAIL PROTECTED]> writes:

> ARCH := $(shell uname -m | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e 
> s/arm.*/arm/ -e s/sa110/arm/
>
> I'm working on polishing my meagre shell scripting skills and would
> appreciate some feedback on the line above, quoted from the kernel Makefile.
>
> 1. How would you use this in a straight bash script so it returned a value
> containing the boxes architecture?

The contents of the $(shell ...) Make fragment should be a valid shell
command.

> 2. As far as comparisons go, if I wanted to determine if a string contained
> ".xyz" or ".abc" would that be a variant of the fragment above?

Two somewhat common ways:

  uname -m | grep i.86 > /dev/null && echo x86

  case `uname -m` in
i?86) echo x86 ;;
  esac


-- 
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 scripting question

2002-11-03 Thread Joshua Lee
On Sun, Nov 03, 2002 at 12:28:26PM -0700, Bob Proulx wrote:
> get around 40,000 files in one single directory.  Some filesystems
> such as JFS (and I think, not sure, XFS and ReiserFS too) store
> directies in B+ trees and are specifically designed to handle large

I know that ReiserFS does this. XFS is supposed to be better for large
files while Reiser is better for small files, but perhaps XFS uses
B-Trees anyway, it seems to have every other feature... ;-)


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




Re: bash scripting question

2002-11-03 Thread Bob Proulx
Neal Lippman <[EMAIL PROTECTED]> [2002-11-03 13:35:22 -0500]:
> Thanks. My "bug" here was using comma instead of space as the separator,
> and not realizing that the reason for x in {a,b,c,d...z} worked was
> because of the way the brace expansion was being done by the shell.

Ah, yes, csh style {one,two,three} expansion.  But not in a string.

> It isn't really the echo statement that is what I need. Actually, I have
> a database organized into subdirectories starting with letters of the
> alphabet (eg /data/A, /data/B, and so on) and within each subdirectory
> are further directories based on people's names. I use the alphabetical
> subdirectories to organize things so I don't have thousands of
> directories in /data.

A wise configuration.  Classic filesystems such as BSD FFS, and
similar like Ext2 and Ext3 have severe degradation problems when you
get around 40,000 files in one single directory.  Some filesystems
such as JFS (and I think, not sure, XFS and ReiserFS too) store
directies in B+ trees and are specifically designed to handle large
databases of files efficiently.  That is the draw of those newer
filesystems.

> The need for the iterator is so that I can scan
> through all the subdirectories, so I often use syntax like:
>   for x in "A B C D ... Z"; do
>   cd $x ;
>   for y in *; do
>   cd $y ;
>   for z in *; do
>   
>   done
>   cd ..
>   done
>   cd ..
>   done
> I was just looking for a shortcut for typing the entire alphabet each
> time. Many of the operations are repeated, so I wrote scripts for them,
> but sometimes I just need to type the syntax by hand to do something,
> and it bothered me that I couldn't figure out the write bash syntax.

But you can.  If all of the directories are there and enumerated them
you can match them with another file glob.  You do something similar
with '*' in the above.  If A-Z are the only directories there then *
would work again.  Or you could be more specific using [A-Z].

for x in [A-Z]; do
cd $x ;
for y in *; do
cd $y ;
for z in *; do

done
cd ..
done
cd ..
done

But that is a lot of 'cd someplace' and loops.  I think they can be
collapsed.

for x in [A-Z]/*/*; do
cd $x ;

cd ../../..
done

I don't like having to remember to back out of the 'cd' and so
whenever possible I try to make it a single line cd and put it in to a
subshell.  The subshell will cd but the parent, this script will not.
When the subshell exits the parent will be at the same place it was
before and there is no possibility of getting your cd down dir and
your cd up dir actions mismatched.

for x in [A-Z]/*/*; do
(cd $x ;  )
done

> Of course, the smart thing is to write a script that takes the desired
> command as a parameter and executes the above loop with that command.

Yes, no, maybe.  Does the above collapse of syntax help?  Hope so.

Bob



msg10800/pgp0.pgp
Description: PGP signature


Re: bash scripting question

2002-11-03 Thread Jesus Climent
On Sat, Nov 02, 2002 at 10:51:00PM -0500, Neal Lippman wrote:
> 
> This works fine if I actually type out the entire alphabet list on the
> command line as above, but that's sort of a pain. So, I tried setting a
> shell variable to the alphabet string (export alpha="A,B,C,...,Z"), but
> then the command:
>   for x in {$alpha} ; 
>   do
>   echo $x;
>   done
> winds up printing the string "{A,B,C,...,Z}" rather than each letter on
> a separate line as expected.
> 

The problem here might be the way the expression is scapped:

After the for, x is substituted by $alpha, so the echo $x shows the
content of $alpha. the curly braquets might take preference over the
variable substitution, so it is used as a one item list, $alpha.

Dunno if is POSIXly correct, but it works that way.

Try using:

alpha="a b c d e" with spaces and

for x in $alpha ; do
echo $x
done

Even trying with your idea and using the execution inverted
single-quotes (`) it is taken as a one-element list, with no comas.

HTH

-- 
Jesus Climent | Unix System Admin | Helsinki, Finland.
web: www.hispalinux.es/~data/  |  pumuki.hispalinux.es
--
Please, encrypt mail sent to me:   GnuPG ID:  86946D69
FP: BB64 2339 1CAA 7064 E429  7E18 66FC 1D7F 8694 6D69
--
Registered Linux user #66350 Debian 3.0 & Linux 2.4.20

- ... todos necesitamos creer en algo.
- Si, yo también creo... Creo... que me voy a tomar una cerveza.
--Sor Trini (Año Mariano)



msg10795/pgp0.pgp
Description: PGP signature


Re: bash scripting question

2002-11-03 Thread Bob Proulx
Neal Lippman <[EMAIL PROTECTED]> [2002-11-02 22:51:00 -0500]:
> I am trying to solve a bash scripting problem, but I cannot figure it
> out.
> 
> I frequently need to execute a command of the form:
>   for x in {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z); do
>;
>   done
> 
> This works fine if I actually type out the entire alphabet list on the
> command line as above, but that's sort of a pain.

Yes, that could be.  Are you refering to literal letters?  Or is that
just an example of a bigger word?

> So, I tried setting a
> shell variable to the alphabet string (export alpha="A,B,C,...,Z"), but
> then the command:
>   for x in {$alpha} ; 
>   do
>   echo $x;
>   done
> winds up printing the string "{A,B,C,...,Z}" rather than each letter on
> a separate line as expected.

A simple syntax error which you have probably already deduced.  Change
that one line to this.

for x in ${alpha} ; 

And in actuality the curly braces are not needed here and in your case
are just getting in the way.  I would not include them in this
particular case.  I only include them when they are needed to split a
string of characters into different variables.

for x in $alpha ;

Also, you need to use spaces instead of commas to seperate your
items.  (Or as another poster almost suggested, set IFS to include the
comma but that would make this script more confusing and I recommend
doing it this way instead.)

  alpha="A B C D E"
  for x in $alpha ; do
echo $x
  done

> I've tried various versions, including escaping the {} characters, etc,
> using xargs, etc, but I cannot hit upon a sequence that works.
> 
> I also tried writing a program that printed the alphabet string to
> stdout, but same results.

You don't really need a variable.  Just run the for-loop.

  for x in A B C D E F G H I J K L M N O P Q R S T U V X Y Z ; do
echo $x
  done

Bob

P.S.  Perl has an operator which might help here.  A snippet from the
perl docs.  Perhaps this might be helpful to take the drudgery out of
walking through a list of letters.  But I will leave implementation as
an exercise to the reader since it starts to look like line noise at
that point.  The above is really simpler to grasp in an instant what
is happening.

   The auto-increment operator has a little extra builtin
   magic to it.  If you increment a variable that is numeric,
   or that has ever been used in a numeric context, you get a
   normal increment.  If, however, the variable has been used
   in only string contexts since it was set, and has a value
   that is not the empty string and matches the pattern
   "/^[a-zA-Z]*[0-9]*\z/", the increment is done as a string,
   preserving each character within its range, with carry:

   print ++($foo = '99');  # prints '100'
   print ++($foo = 'a0');  # prints 'a1'
   print ++($foo = 'Az');  # prints 'Ba'
   print ++($foo = 'zz');  # prints 'aaa'

   The auto-decrement operator is not magical.

Quick example of use:

  perl -le "print ++(\$foo = 'A')"
  B



msg10787/pgp0.pgp
Description: PGP signature


Re: bash scripting question

2002-11-03 Thread Bob Proulx
[EMAIL PROTECTED] <[EMAIL PROTECTED]> [2002-11-03 18:15:06 +0200]:
> On Sat, Nov 02, 2002 at 10:05:45PM -0600, Michael Heironimus wrote:
> > alpha="a b c d e  z"
> > for x in $alpha ; do
> > echo $x
> > done
> > 
> > I think this should work in any Bourne-style shell
> 
> Doesn't work for me in bash:
> 
> $ for x in "a b c d e  z"; do printf "$x "; done; printf "\n"
> a b c d e  z 
> $

I believe they were using ... as a euphemism to say fill in the entire
sequence literally.

> As for the original poster, an ugly solution might be with seq and tr:
> 
> $ for x in $(seq 1 5); do export y=$(printf "$x" | tr 1-5 a-e); printf
> "$y "; done; printf "\n" 
> a b c d e 

Very cute!  I like it.

Bob



msg10783/pgp0.pgp
Description: PGP signature


Re: bash scripting question

2002-11-03 Thread Bob Proulx
Matthias Hentges <[EMAIL PROTECTED]> [2002-11-03 18:32:29 +0100]:
> Am Son, 2002-11-03 um 04.51 schrieb Neal Lippman:
> > I frequently need to execute a command of the form:
> > for x in {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z); do
> Your problem ist the wrong setting of the IFS (man bash, search for IFS)
> TARGETS="A B C D E F G H I"   #set up list of targets
> OLD_IFS="$IFS"#remember old IFS 
> IFS=" "   #set IFS to "space"
> [...use it...]
> IFS="$OLD_IFS"#restore old IFS
> 
> That's how i do it all the time. There may be a better way, but it Just
> Works (TM)

The default setting of IFS is "", which I show
typed out because none of those are printable.  Changing it to a space
only would only be needed if something had already previously changed
it to something else.  I believe suggesting to people that they should
set it to a space out of context will be confusing.

You would only need to change it to a space if previously you had set
IFS to something else that did not contain a space.  If they did not
do that previously then they do not need to do this here.  The problem
must be something else.  In this case I think it is confusion about
walking through a list of items.

Bob



msg10782/pgp0.pgp
Description: PGP signature


Re: bash scripting question

2002-11-03 Thread Matthias Hentges
Am Son, 2002-11-03 um 04.51 schrieb Neal Lippman:
> I am trying to solve a bash scripting problem, but I cannot figure it
> out.
> 
> I frequently need to execute a command of the form:
>   for x in {A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z); do
>;
>   done
> 
> This works fine if I actually type out the entire alphabet list on the
> command line as above, but that's sort of a pain. So, I tried setting a
> shell variable to the alphabet string (export alpha="A,B,C,...,Z"), but
> then the command:
>   for x in {$alpha} ; 
>   do
>   echo $x;
>   done
> winds up printing the string "{A,B,C,...,Z}" rather than each letter on
> a separate line as expected.
> 
> I've tried various versions, including escaping the {} characters, etc,
> using xargs, etc, but I cannot hit upon a sequence that works.
> 
> I also tried writing a program that printed the alphabet string to
> stdout, but same results.
> 
> Can anyone suggest a syntax that would do the trick here?

Your problem ist the wrong setting of the IFS (man bash, search for IFS)

!#/bin/bash

TARGETS="A B C D E F G H I" #set up list of targets
OLD_IFS="$IFS"  #remember old IFS 
IFS=" " #set IFS to "space"

for x in $TARGETS
do
something $x
done

IFS="$OLD_IFS"  #restore old IFS

That's how i do it all the time. There may be a better way, but it Just
Works (TM)
-- 

Matthias Hentges
[www.hentges.net] -> PGP + HTML are welcome
ICQ: 97 26 97 4   -> No files, no URLs

My OS: Debian Woody: Geek by Nature, Linux by Choice


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




Re: bash scripting question

2002-11-03 Thread shaulka
On Sat, Nov 02, 2002 at 10:05:45PM -0600, Michael Heironimus wrote:
> On Sat, Nov 02, 2002 at 10:51:00PM -0500, Neal Lippman wrote:
> > shell variable to the alphabet string (export alpha="A,B,C,...,Z"), but
> > then the command:
> > for x in {$alpha} ; 
> > do
> > echo $x;
> > done
> > winds up printing the string "{A,B,C,...,Z}" rather than each letter on
> > a separate line as expected.
> 
> alpha="a b c d e  z"
> for x in $alpha ; do
> echo $x
> done
> 
> I think this should work in any Bourne-style shell
> 
> -- 
> Michael Heironimus
> 


Doesn't work for me in bash:

$ for x in "a b c d e  z"; do printf "$x "; done; printf "\n"
a b c d e  z 
$

As for the original poster, an ugly solution might be with seq and tr:

$ for x in $(seq 1 5); do export y=$(printf "$x" | tr 1-5 a-e); printf
"$y "; done; printf "\n" 
a b c d e 
$
-- 

Shaul Karl, [EMAIL PROTECTED] e t


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




Re: bash scripting question

2002-11-02 Thread Michael Heironimus
On Sat, Nov 02, 2002 at 10:51:00PM -0500, Neal Lippman wrote:
> shell variable to the alphabet string (export alpha="A,B,C,...,Z"), but
> then the command:
>   for x in {$alpha} ; 
>   do
>   echo $x;
>   done
> winds up printing the string "{A,B,C,...,Z}" rather than each letter on
> a separate line as expected.

alpha="a b c d e  z"
for x in $alpha ; do
echo $x
done

I think this should work in any Bourne-style shell

-- 
Michael Heironimus


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




Thank you all! (Was: Re: bash scripting question (variables and spaces))

2002-03-20 Thread Karsten Heymann
Thank you all! Now it works.

* Gustavo Noronha Silva <[EMAIL PROTECTED]> [020320 09:25]:
...
> C="$A $B"

-- 
Karsten Heymann <[EMAIL PROTECTED]> <[EMAIL PROTECTED]>
CAU-University Kiel, Germany
Registered Linux User #221014  (http://counter.li.org)



Re: bash scripting question (variables and spaces)

2002-03-19 Thread Brett Parker
On Tue, Mar 19, 2002 at 08:35:53PM +0100, Karsten Heymann wrote:
> Hi,
> 
> I have once again come upon bash problem I can't solve. I'm writing a
> little bash frontend and one of the programs expects a option that includes
> spaces and is composed from two other shell var's. Example:
> 
> #!/bin/bash
> A="Hello"
> B="Karsten"
> C=$A $B 
> someprog --greeting $C
  ^^
  this is the problem... try...
  someprog --greeting "$C"

That should work, I think.

Cheers,

Brett



pgpqOubytSIwG.pgp
Description: PGP signature


Re: bash scripting question (variables and spaces)

2002-03-19 Thread Angus D Madden
Karsten Heymann, Tue, Mar 19, 2002 at 08:35:53PM +0100: 
> Hi,
> 
> I have once again come upon bash problem I can't solve. I'm writing a
> little bash frontend and one of the programs expects a option that includes
> spaces and is composed from two other shell var's. Example:
> 
> #!/bin/bash
> A="Hello"
> B="Karsten"
> C=$A $B 
> someprog --greeting $C
> 
> Whatever I do now, --greeting receices only the "Hello" part. I've
> tried some other variants too:
> 
> C="$A $B"
> C=\"$A $a\B"
> C='$A $B'
> C=$A\ $B
> C=`echo $A $B`
> 
> What works is 
> someprog --greeting "Hello Karsten"
> but that's no solution.
> 

Try this:

#!/bin/bash
A="Hello"
B="World"
C="$A $B"

someprog --greeting "$C"


That should do it for you.

g



-- 
Brought to you by Debian 3.0
Linux took 2.4.16 #1 SMP Sat Jan 5 12:52:24 EST 2002 i686 unknown


pgp6BtsJUqm3M.pgp
Description: PGP signature


Re: bash scripting question (variables and spaces)

2002-03-19 Thread Gustavo Noronha Silva
On Tue, 19 Mar 2002 20:35:53 +0100
Karsten Heymann <[EMAIL PROTECTED]> wrote:

> Hi,
> 
> I have once again come upon bash problem I can't solve. I'm writing a
> little bash frontend and one of the programs expects a option that includes
> spaces and is composed from two other shell var's. Example:
> 
> #!/bin/bash
> A="Hello"
> B="Karsten"
> C=$A $B 
> someprog --greeting $C
try someprog --greeting "$C", that should work... indeed, I think
you should do:

C="$A $B"

also

[]s!

-- 
[EMAIL PROTECTED]: Gustavo Noronha 
Debian:  * 



Re: bash scripting question (variables and spaces)

2002-03-19 Thread David Z Maze
Karsten Heymann <[EMAIL PROTECTED]> writes:
> Hi,
> 
> I have once again come upon bash problem I can't solve. I'm writing
> a little bash frontend and one of the programs expects a option that
> includes spaces and is composed from two other shell var's. Example:
> 
> #!/bin/bash
> A="Hello"
> B="Karsten"
> C=$A $B 
> someprog --greeting $C

You need something like

#!/bin/sh
A=Hello
B=Karsten
C="$A $B"
someprog --greeting "$C"

Without the quotes, the shell expands things to

someprog --greeting Hello Karsten

which then gets turned into arguments "someprog", "--greeting",
"Hello", "Karsten"; presumably someprog only reads a single argument
after --greeting, and gets just "Hello".

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



Re: bash scripting question (variables and spaces)

2002-03-19 Thread Paul F. Pearson
On Tue, 19 Mar 2002, Karsten Heymann wrote:

> Hi,
> 
> I have once again come upon bash problem I can't solve. I'm writing a
> little bash frontend and one of the programs expects a option that includes
> spaces and is composed from two other shell var's. Example:
> 
> #!/bin/bash
> A="Hello"
> B="Karsten"
> C=$A $B 
> someprog --greeting $C
> 
> Whatever I do now, --greeting receices only the "Hello" part. I've
> tried some other variants too:
> 
> C="$A $B"
> C=\"$A $a\B"
> C='$A $B'
> C=$A\ $B
> C=`echo $A $B`
> 
> What works is 
> someprog --greeting "Hello Karsten"
> but that's no solution.

try someprot --greeting "$A $B"

There's an excelleng bash scripting HOWTO (don't know the URL right of the 
top of my head) that should be very useful.

> 
> Please help :-)
> 
> Karsten
> 
> 

-- 
Paul F. Pearson ([EMAIL PROTECTED]) http://home.hiwaay.net/~ppearson/
"Lord heal our land. Father heal our land. Hear our cry and turn our nation 
back to You" - Heal Our Land, _Magnify The Lord_ (Integrity Music)



Re: bash scripting question (variables and spaces)

2002-03-19 Thread J.H.M. Dassen \(Ray\)
On Tue, Mar 19, 2002 at 20:35:53 +0100, Karsten Heymann wrote:
> A="Hello"
> B="Karsten"
> C=$A $B 
> someprog --greeting $C

Variable expansion happens first:
someprog --greeting Hello Karsten
then tokenising, so someprog get three arguments:
1. --greeting
2. Hello
3. Karsten
whereas you want it to get two arguments:
1. --greeting
2. Hello Karsten
in which case you need double quotes around $C to prevent it from being
split into multiple tokens:
someprog --greeting "$C"

HTH,
Ray
-- 
"People should never have been given free will."  Lots of languages.
Larry Wall on common fallacies of language design



Re: bash scripting question (variables and spaces)

2002-03-19 Thread ktb
On Tue, Mar 19, 2002 at 08:35:53PM +0100, Karsten Heymann wrote:
> Hi,
> 
> I have once again come upon bash problem I can't solve. I'm writing a
> little bash frontend and one of the programs expects a option that includes
> spaces and is composed from two other shell var's. Example:
> 
> #!/bin/bash
> A="Hello"
> B="Karsten"
> C=$A $B 
> someprog --greeting $C
> 

#!/bin/bash
A="Hello"
B="Karsten"
C="$A $B"

echo "$C"

Works fine for me.  

[EMAIL PROTECTED]:~/scratch$ ./yo2
Hello Karsten

What is your "someprog" ?
kent

-- 
To know the truth is to distort the Universe.
  Alfred N. Whitehead (adaptation)



Re: bash scripting question (variables and spaces)

2002-03-19 Thread Craig Dickson
This should work, though I have not actually tried it:

#!/bin/bash
A="Hello"
B="Karsten"
C="$A $B"
someprog --greeting "$C"


pgpiX8Z2JqpWm.pgp
Description: PGP signature


Re: Bash Scripting

2001-01-31 Thread John Hasler
D-Man writes:
> If he wants to start with bash he can.  I think bash scripting is harder
> than python though.

Poor shell programming is quite easy.  Good shell progamming is harder than
good Python programming.
-- 
John Hasler
[EMAIL PROTECTED]
Dancing Horse Hill
Elmwood, Wisconsin



Re: Bash Scripting

2001-01-31 Thread D-Man
On Tue, Jan 30, 2001 at 10:55:53PM +0100, William Leese wrote:
[snip] 
| > BTW,  I don't use bash scripting for anything other than running
| > programs with some default options.  I would prefer to use python for
| > this sort of thing, but it's up to you what you want to use.
| 
| ..let the newbie get used to bash first okay? ;)

If he wants to start with bash he can.  I think bash scripting is
harder than python though.

-D



Re: Bash Scripting

2001-01-30 Thread Nate Bargmann
On Tue, Jan 30, 2001 at 09:40:53PM +0100, William Leese wrote:
> hi all
> 
> i need a little help on a script. the following scripts function is to merge 
> several parts of a html page together and insert a new piece of text from 
> text.txt also it has to replace some words (the title, author, submittor, and 
> date) with the words given at prompt.

No expert at shell scripting, but based on your description of what
you're trying to do, have you looked at WSMake (http://www.wsmake.org)?
I've used it for over a year doing the things you seem to be trying to
accomplish.

- Nate >>

-- 
 Wireless | Amateur Radio Station N0NB  | "None can love freedom
 Internet | [EMAIL PROTECTED]   | heartily, but good
 Location | Wichita, Kansas USA EM17hs  | men; the rest love not
   Wichita area exams; ham radio; Linux info @  | freedom, but license."
 http://www.qsl.net/n0nb/   | -- John Milton



Re: Bash Scripting

2001-01-30 Thread Oliver Elphick
D-Man wrote:
  >sed  "s/Title/$TITLE/g" title.html >> file.txt &&
  >
  >Also, I'm not sure why you have double & at the end of the line.  I
  >think you want to run sed in the foreground, not the background.  I
  >don't understand what the second & does.
 
  & by itself mean s to run in the background

  && means run the next pipeline only if the current command has a zero
 exit status

  || means run the next pipeline if the current command has a non-zero
 exit status


Thus

  grep -qs 'some garbage' input_file && echo Found it || echo Not there

-- 
Oliver Elphick[EMAIL PROTECTED]
Isle of Wight  http://www.lfix.co.uk/oliver
PGP: 1024R/32B8FAA1: 97 EA 1D 47 72 3F 28 47  6B 7E 39 CC 56 E4 C1 47
GPG: 1024D/3E1D0C1C: CA12 09E0 E8D5 8870 5839  932A 614D 4C34 3E1D 0C1C
 
 "The Lord knoweth how to deliver the godly out of 
  temptations, and to reserve the unjust unto the day of
  judgment to be punished;"II Peter 2:9 




Re: Bash Scripting

2001-01-30 Thread William Leese

> | > sed  's/Title/$TITLE/g' title.html >> file.txt &&
>
>  ^^
> The single quotes are a problem too.  Bash doesn't do any variable
> expansion in single quotes.  ($TITLE will still be $TITLE for sed)
>
> Instead:
>
> sed  "s/Title/$TITLE/g" title.html >> file.txt &&
>
> Also, I'm not sure why you have double & at the end of the line.  I
> think you want to run sed in the foreground, not the background.  I
> don't understand what the second & does.

heh, ofcourse.. 

> | I think the g is missing, that is all I noticed
>
> You only need the g if the text to replace occurs more than once on a
> line.  If it doesn't, it doesn't matter.  If it does, do you want to
> replace all occurences or just the first?

its just a one time one word replace..

> BTW,  I don't use bash scripting for anything other than running
> programs with some default options.  I would prefer to use python for
> this sort of thing, but it's up to you what you want to use.

..let the newbie get used to bash first okay? ;)

Cheers,

William



RE: Bash Scripting

2001-01-30 Thread Sean 'Shaleh' Perry

On 30-Jan-2001 William Leese wrote:
> hi all
> 
> i need a little help on a script. the following scripts function is to merge 
> several parts of a html page together and insert a new piece of text from 
> text.txt also it has to replace some words (the title, author, submittor, and
> date) with the words given at prompt.
> 
> (i'm aware that its crude and basic, but i'm not familar with scripting for 
> bash though i'm working through the HOWTO)
> 
> the problem is that the variables TITLE AUTHOR SUBMITTOR DATE are not 
> replaced with the inputted values, where as FILENAME is so i must have the 
> synax wrong the "/"s perhaps?
> 


your script is actually a /bin/sh script and uses no special bash features.


$ export FOO="Hi"
$ echo 'bye cruel world!' | sed -e "s/bye/$FOO/"
Hi cruel world!

The problem is you used "'" as your quote char aka single quotes.  In shell,
single quote means "pass me along without looking".  You want double quotes
like I used.



Re: Bash Scripting

2001-01-30 Thread D-Man

On Tue, Jan 30, 2001 at 10:02:38PM +0100, Matthias Wieser wrote:
| William Leese wrote:
|  
| > sed  's/Title/$TITLE/g' title.html >> file.txt &&
 ^^
The single quotes are a problem too.  Bash doesn't do any variable
expansion in single quotes.  ($TITLE will still be $TITLE for sed)

Instead:

sed  "s/Title/$TITLE/g" title.html >> file.txt &&

Also, I'm not sure why you have double & at the end of the line.  I
think you want to run sed in the foreground, not the background.  I
don't understand what the second & does.

| I think the g is missing, that is all I noticed

You only need the g if the text to replace occurs more than once on a
line.  If it doesn't, it doesn't matter.  If it does, do you want to
replace all occurences or just the first?

| 
| Ciao, mattHias
| 
| -- 


BTW,  I don't use bash scripting for anything other than running
programs with some default options.  I would prefer to use python for
this sort of thing, but it's up to you what you want to use.

-D



Re: Bash Scripting

2001-01-30 Thread Matthias Wieser
William Leese wrote:
 
> sed  's/Title/$TITLE/g' title.html >> file.txt &&
   ^
I think the g is missing, that is all I noticed

Ciao, mattHias

-- 
   __   _   __   *
/\_/\  \ \_/ \_/ /   *  Matthias Wieser  *
   / \  \   /*  ICQ#:  12597522  *
  / /\_/\ \  \_/^\_/ *[EMAIL PROTECTED]   *
  WW WW  *



RE: Bash scripting problem

2000-05-02 Thread Christophe ABRIAL
Hello,

If you read the man about bash, you will find out that all commands after a
pipeline are executed in a subshell.
It's not a bash bug !

Perhaps, if you try this :

#!/bin/bash -e

found_driver=0
echo -n "Starting sound driver: "
while read line; do
  if /sbin/modprobe $line >/dev/null 2>&1; then
echo "$line"
found_driver=1
echo "DEBUG1: found_driver=$found_driver"
  fi
  echo "DEBUG2: found_driver=$found_driver"
done < awk '/^alias +snd-card-[0-9]/ {print $3}' /etc/modules.conf
echo "DEBUG3: found_driver=$found_driver"

Hope it's help!

Christophe Abrial
LSA France
Systems and Networks Solutions

-Message d'origine-
De : Martin Fluch [mailto:[EMAIL PROTECTED]
Envoye : mardi 2 mai 2000 09:43
A : debian-user@lists.debian.org
Objet : Bash scripting problem


Hi all!

On my woody box I ran into the following problem:

After I had problem with the /etc/init.d/alsa script I started to track
down the problem and finaly ended with the following script, which doesn't
work like I expect:

#!/bin/bash -e

found_driver=0
echo -n "Starting sound driver: "
awk '/^alias +snd-card-[0-9]/ {print $3}' /etc/modules.conf | \
while read line; do
  if /sbin/modprobe $line >/dev/null 2>&1; then
echo "$line"
found_driver=1
echo "DEBUG1: found_driver=$found_driver"
  fi
  echo "DEBUG2: found_driver=$found_driver"
done
echo "DEBUG3: found_driver=$found_driver"

When I execute this, I get the following output:

[EMAIL PROTECTED]:/etc/init.d> ./alsa.debug
Starting sound driver: snd-card-cs4236
DEBUG1: found_driver=1
DEBUG2: found_driver=1
DEBUG3: found_driver=0

What me puzzles is: why is finaly $found_driver reseted to 0? Is this a
bash bug (bash --version gives "GNU bash, version 2.04.0(1)-release
(i386-pc-linux-gnu) ...")?

Martin



--
Unsubscribe?  mail -s unsubscribe [EMAIL PROTECTED] <
/dev/null


Re: bash scripting

1999-07-26 Thread Kent West
"Carley, Jason (Australia)" wrote:

> >The kindest thing you can do for anyone in difficulty is to persuade him
> >that he really does need to study the manual.
>
> >He shouldn't even be posting questions until he has looked into the matter
> >himself and drawn a blank on all fronts.  So any question answered in the
> >manual deserves either to be totally ignored or to be flamed.  It does NOT
> >deserve an answer.
>
> This is a bit strong isn't it? Sometimes newbies don't know how to find the
> answer themselves. Unfortunately UNIX skills are not inherently obvious to
> all and the information that you find so easy to obtain can sometimes be
> tricky for newbies. Hence all the recent discussions on a newbies
> information guide.
>
> Of course people should be encouraged to read the manual pages. But a polite
> answer that helps the new user AND points them to where they could have
> found it themselves is likely to result in more people taking the time to
> learn Linux. To "be totally ignored or ... flamed" is hardly the appropriate
> response I am afraid.

>

I agree, Jason. I'm not the original poster, but I just now pretended to want 
the
same question answered (how to put a 30-second delay in a script). I thought to
myself, I'll look in "man bash". I did a search on "delay", and on "wait", and 
on
"sleep". "sleep", which was the answer to the original problem, was not even 
found in
the bash manual. "delay" and "wait" had no relevance to the problem. So I tried 
"man
script". The script man page had nothing to do with scripting (and didn't have 
any of
the three above-mentioned search words). So as a person looking for the answer, 
and
knowing that I'm going to be told to RTFM, I wonder, "Which manual am I 
supposed to
read for this?" After the fact, I know the correct command is "sleep"; but I 
still
don't know where to find that info; the only place I've seen it mentioned is in 
this
thread.

Oh, I just thought to use the "apropos delay" command; it did turn up the 
"sleep"
command, but again, that's not an intuitive step for the non-initiated.

I guess what I'm saying is that the uninitiated (newbie or not; he's new to this
particular thing) doesn't always know what manual to read, so just yelling RTFM 
isn't
a good solution. Generally when I have a question, my first source of help is 
the
Debian userlist archives, but even that took me a few months to realize the 
correct
search engine to use was at the bottom of the archive page, not the (site-) 
search
button at the top.

I understand Michael's frustration at having to answer the same questions 500 
times.
Maybe a big bold link on the Debian home page that says "Have a question? Look 
here
first" which takes the user directly to the search input box on the mail archive
search engine?


Re: bash scripting

1999-07-26 Thread Michael Stenner
On Mon, Jul 26, 1999 at 05:24:11PM +0930, Michael Talbot-Wilson wrote:

> > I love how people insist on firing off this remark. It is sooo
> > much more explanatory than pasting in a piece of the manpage then
> > breaking it down to a newbies' terms. Then _calmly_ telling them
> > (OFF THE LIST) that they should RTFM without using the RTFM
> > flame. I just think we spend way too much time falming, and not
> > enough time correcting these people who neglect to read

> People start to say it after they have politely answered the same 
> question approximately 500 times.

That's understandable, but I still discourage it.

> There are about 10,000 new newbies coming onto the Internet every day

This is precisely the point.  While it may be your 500th time to hear
an easy, well-documented problem, it's not fair that when a frustrated
newbie finally musters the courage to send email to several thousand
people, he gets slapped in the face with RTFM.

If it's a cronic offender, then fine, nail 'em, but it's a pretty
rough welcome for those who may not know any better.  Hell, early in
my linux career, I was getting slapped with "RTFM" and didn't even
know what it stood for -- that was useful!

> all with the same cluelessness and the same questions.  Every day, every 
> week, every month, every year.  

(I say this politely, really) Those who cannot tolerate this should
probably not respond.  There are others (perhaps those, like me, fresh
out of newbie-school themselves) who will be happy to gently steer
newbies rather than slam them in the right direction.

> The manual should only need to be written once, not thousands of times.  
> The person who did write it is usually best qualified to do so.  You seem 
> to think anyone else in the world can express the matter better than the 
> original author.  If you were to read the bash manual page yourself you 
> would see that it is a brilliant piece of writing that no-one is going to 
> better.

I agree, but it can be overwhelming.  I was a solid linux user for
a long time before I made it through that man page.  (forgive the
physics anology)  You shouldn't hand a high school kid Jackson
(graduate electricity and magnetism) when he asks how electromagnets
work.  It's just too much.

> The kindest thing you can do for anyone in difficulty is to persuade him 
> that he really does need to study the manual.

Agreed, the only way he'll ever make it though the manual is by trying
_many_ times.

> He shouldn't even be posting questions until he has looked into the matter
> himself and drawn a blank on all fronts.  

I typically say you should ask for help after scratching your head
(i.e. NO ideas) for 1/2 hour.

> So any question answered in the manual deserves either to be totally
> ignored or to be flamed.  It does NOT deserve an answer.

Now that's productive.  I would think that even the most cynical
oldbie would at least point them to the manual in case they don't know
where it is.

> It is bad netiquette to paste part of the man page, because it creates 
> traffic delivering something that the recipient already has.  And no-one 
> owes the newbie that kind of favor.  He can cut from the man page 
> himself.  He has it, and he can do it.  The rest of us are busy people 
> and life is running out.  Help where it is needed is one thing.  A crutch 
> for the lazy, or foolishly trying to do for someone else what he must 
> surely do for himself, merely because he sent a message out into the wide 
> world, is quite another.

I agree with this entire statement.  I just think that there is some
middle ground between help for the desperate and a crutch for the
lazy.  The origin of this thread is the perfect example.  The word
"sleep" doesn't even appear in the bash man page.  man sleep will
work, but you first need to know you're looking for sleep.  catch 22.
Appropriate action?  Ask.

-Michael

-- 
  Michael Stenner   Office Phone: 919-660-2513
  Duke University, Dept. of Physics   [EMAIL PROTECTED]
  Box 90305, Durham N.C. 27708-0305


Re: bash scripting

1999-07-26 Thread Wayne Topa

Subject: RE: bash scripting
Date: Mon, Jul 26, 1999 at 06:03:35PM +1000

In reply to:Carley, Jason Australia"

Quoting Carley, Jason Australia"([EMAIL PROTECTED]):
> 
> >The kindest thing you can do for anyone in difficulty is to persuade him 
> >that he really does need to study the manual.
> 
> >He shouldn't even be posting questions until he has looked into the matter
> >himself and drawn a blank on all fronts.  So any question answered in the
> >manual deserves either to be totally ignored or to be flamed.  It does NOT
> >deserve an answer.

[ snip ]

> learn Linux. To "be totally ignored or ... flamed" is hardly the appropriate
> response I am afraid.

Just another example why we _need_ a weekly posting of "The newbie
Guide-lines for asking questions"  It would seem!

-- 
Who's General Failure and why's he reading my disk?
___
Wayne T. Topa <[EMAIL PROTECTED]>


Re: bash scripting

1999-07-26 Thread Michael Talbot-Wilson
> 
> >The kindest thing you can do for anyone in difficulty is to persuade him 
> >that he really does need to study the manual.
> 
> >He shouldn't even be posting questions until he has looked into the matter
> >himself and drawn a blank on all fronts.  So any question answered in the
> >manual deserves either to be totally ignored or to be flamed.  It does NOT
> >deserve an answer.
> 
> This is a bit strong isn't it? Sometimes newbies don't know how to find the

A bit, but only a bit.  And the first quoted para not at all.


RE: bash scripting

1999-07-26 Thread Carley, Jason \(Australia\)

>The kindest thing you can do for anyone in difficulty is to persuade him 
>that he really does need to study the manual.

>He shouldn't even be posting questions until he has looked into the matter
>himself and drawn a blank on all fronts.  So any question answered in the
>manual deserves either to be totally ignored or to be flamed.  It does NOT
>deserve an answer.

This is a bit strong isn't it? Sometimes newbies don't know how to find the
answer themselves. Unfortunately UNIX skills are not inherently obvious to
all and the information that you find so easy to obtain can sometimes be
tricky for newbies. Hence all the recent discussions on a newbies
information guide.

Of course people should be encouraged to read the manual pages. But a polite
answer that helps the new user AND points them to where they could have
found it themselves is likely to result in more people taking the time to
learn Linux. To "be totally ignored or ... flamed" is hardly the appropriate
response I am afraid.


Re: bash scripting

1999-07-26 Thread Michael Talbot-Wilson
 
> On Mon, Jul 26, 1999 at 08:18:48AM +0200, Gerhard Kroder wrote:
> 
> > ever RTFM for bash? it says:
> 
>   I love how people insist on firing off this remark. It is sooo much more
> explanatory than pasting in a piece of the manpage then breaking it
> down to a newbies' terms. Then _calmly_ telling them (OFF THE LIST) that th=
> ey
> should RTFM without using the RTFM flame. I just think we spend way too much
> time falming, and not enough time correcting these people who neglect to re=
> ad
> the docs. Just my 2 cents.

People start to say it after they have politely answered the same 
question approximately 500 times.

There are about 10,000 new newbies coming onto the Internet every day, 
all with the same cluelessness and the same questions.  Every day, every 
week, every month, every year.  

The manual should only need to be written once, not thousands of times.  
The person who did write it is usually best qualified to do so.  You seem 
to think anyone else in the world can express the matter better than the 
original author.  If you were to read the bash manual page yourself you 
would see that it is a brilliant piece of writing that no-one is going to 
better.

The kindest thing you can do for anyone in difficulty is to persuade him 
that he really does need to study the manual.

He shouldn't even be posting questions until he has looked into the matter
himself and drawn a blank on all fronts.  So any question answered in the
manual deserves either to be totally ignored or to be flamed.  It does NOT
deserve an answer.

It is bad netiquette to paste part of the man page, because it creates 
traffic delivering something that the recipient already has.  And no-one 
owes the newbie that kind of favor.  He can cut from the man page 
himself.  He has it, and he can do it.  The rest of us are busy people 
and life is running out.  Help where it is needed is one thing.  A crutch 
for the lazy, or foolishly trying to do for someone else what he must 
surely do for himself, merely because he sent a message out into the wide 
world, is quite another.


Apologising for Re: bash scripting

1999-07-26 Thread Gerhard Kroder
Gerhard Kroder wrote:
> 
> Gerhard Kroder wrote:
> >
> > [EMAIL PROTECTED] wrote:
> > >
> > > Is there a way to put a 30 second pause in your bash script?
> >
> > ever RTFM for bash? it says:
> >
> >wait [n]


hey, shame on me, i know,... sorry, 

my working day just starts and i'm not quite awaken. and i was too fast
with replying, and usually i don't use _this_ term, and anything 

and thanks for your hints :-)

anyway, how come your responses came in as fast as my first dementi?  ;-)

 gerhard


Re: bash scripting

1999-07-26 Thread Ben Lutgens
On Mon, Jul 26, 1999 at 08:18:48AM +0200, Gerhard Kroder wrote:

> ever RTFM for bash? it says:

I love how people insist on firing off this remark. It is sooo much more
explanatory than pasting in a piece of the manpage then breaking it
down to a newbies' terms. Then _calmly_ telling them (OFF THE LIST) that they
should RTFM without using the RTFM flame. I just think we spend way too much
time falming, and not enough time correcting these people who neglect to read
the docs. Just my 2 cents. 

-- 

"Give a man a fish, and you feed him for a day. 
Teach a man to fish, and you feed him for a lifetime."

Ben Lutgens (pgp public key is "blutgens" available @ hkp://pgpkeys.mit.edu)


pgpITFw20WCue.pgp
Description: PGP signature


RE: bash scripting

1999-07-26 Thread Carley, Jason \(Australia\)
>ever RTFM for bash? it says:

   wait [n]
  Wait  for the specified process and return its ter­
  mination status.  n may be a process ID  or  a  job
  specification;  if  a  job  spec is given, all pro­
  cesses in that job's pipeline are waited for.  If n
  is  not given, all currently active child processes
  are waited for, and the return status is zero.   If
  n  specifies  a  non-existent  process  or job, the
  return status is 127.  Otherwise, the return status
  is  the  exit  status  of  the  last process or job
  waited for.


I think sleep is the appropriate command.

Methinks one should beware of using the evil RTFM term lest it turns and
hits one in the face! :-)


Re: bash scripting

1999-07-26 Thread Matthew Gregan
On Mon, Jul 26, 1999 at 08:18:48AM +0200, Gerhard Kroder wrote:
> [EMAIL PROTECTED] wrote:
> > 
> > Is there a way to put a 30 second pause in your bash script?
> 
> 
> ever RTFM for bash? it says:
> 
>wait [n]

Erm, how exactly can you use this to wait for 30 seconds? I think he
wants something along the lines of sleep.

-- 
Matthew Gregan  [EMAIL PROTECTED]


Re: bash scripting

1999-07-26 Thread Gerhard Kroder
Gerhard Kroder wrote:
> 
> [EMAIL PROTECTED] wrote:
> >
> > Is there a way to put a 30 second pause in your bash script?
> 
> ever RTFM for bash? it says:
> 
>wait [n]

huups, guess it's me to RTFM...

of course you do not need (nor is it applicable) bash's builtin "wait" but
the commmand "sleep" (man sleep).

gerhard


Re: bash scripting

1999-07-26 Thread Gerhard Kroder
[EMAIL PROTECTED] wrote:
> 
> Is there a way to put a 30 second pause in your bash script?


ever RTFM for bash? it says:

   wait [n]
  Wait  for the specified process and return its ter­
  mination status.  n may be a process ID  or  a  job
  specification;  if  a  job  spec is given, all pro­
  cesses in that job's pipeline are waited for.  If n
  is  not given, all currently active child processes
  are waited for, and the return status is zero.   If
  n  specifies  a  non-existent  process  or job, the
  return status is 127.  Otherwise, the return status
  is  the  exit  status  of  the  last process or job
  waited for.

ok?

 gerhard


Re: bash scripting

1999-07-25 Thread Bernhard Rieder
[EMAIL PROTECTED] wrote:
> 
> Is there a way to put a 30 second pause in your bash script?
> 
sleep 30

You can also use s,m,h,d for seconds, minutes, hours and days
ie. sleep 1h

Bernhard
-- 
  __ ___
 // )___--"""-.
\ |,"( /`--""  `. Bernhard Rieder
 \/ o\
 (   _.-.  ,'";   mail: [EMAIL PROTECTED]
  |\"   /`. \  ,  /   |
  | \  ' .'`.; |  |   \.___
_-'.'| |--..,,,\_\-~"""
   '''"   _-'.'   ___"-   )
 '''"'''---~""


Re: bash scripting

1999-07-25 Thread Matthew Gregan
On Sun, Jul 25, 1999 at 12:53:58AM -0500, [EMAIL PROTECTED] wrote:
> Is there a way to put a 30 second pause in your bash script?

Use:

sleep 30s

'man sleep' for more info. :-)

-- 
Matthew Gregan  [EMAIL PROTECTED]


Re: bash scripting

1999-07-25 Thread Noah L. Meyerhans
-BEGIN PGP SIGNED MESSAGE-

On Sun, 25 Jul 1999 [EMAIL PROTECTED] wrote:

> Is there a way to put a 30 second pause in your bash script?
> 

sleep 30

See man 1 sleep.

noah

  PGP public key available at
  http://lynx.dac.neu.edu/home/httpd/n/nmeyerha/mail.html
  or by 'finger -l [EMAIL PROTECTED]'



-BEGIN PGP SIGNATURE-
Version: 2.6.2

iQCVAwUBN5sNi4dCcpBjGWoFAQG9tAQAtwORn+xwrfMzh8x1xN/tqQok5Zo0Qkn/
wnmoLxaXRue/QW7meP2fvS9Ccr1QNKfcpjtBPpmI6oB41MjXdsUctVASQnZxLxeU
bDhs0hDHrmNbuGFhd54/NVyRpZxIbyibyubiXnNIS7WtFEgsBUebw5v1cRDftaBx
mQ5lBxMhOpM=
=ENrW
-END PGP SIGNATURE-


Re: bash scripting

1999-02-12 Thread David S. Zelinsky
Eugene Sevinian <[EMAIL PROTECTED]> writes:

> Hi, ppl, 
> I would like to know, is it possible to fork the standard stdout
> of some command into another two or three pipelines. The idea is to avoid
> unnecessary disk load during temporary file writing/reading. So I need
> something like this:
> 
> command1 | command2 | command3 | command4 > file1 
>  \->command5 | command6 > file2
>   \->command7 | command8 > file3   
> 
> Does bash allow such things?


I can't think of any elegant way to do what you want; I was hoping someone
else would come up with one.  Since no one has, here's an inelegant solution.

Someone suggested using `tee', which does split the output stream the way you
want.  Unfortunately, tee can only send one copy of the output to a pipe; the
rest must be to files.  The trick is to make those files be named pipes. (Also
called a `fifo', a named pipe is a special file, which one process can write
to while another process reads from it, having the same effect as a
command-line pipe.  Nothing actually gets stored on disk.)

Here's how to do it, using your example below:

  % mkfifo fifo1 fifo2
  % command1 | command2 | tee fifo1 fifo2 | command3 | command4 >file1 \
& command5 file2 \
& command7 file3

The `mkfifo' command creates two named pipes, called fifo1 and fifo2, in the
current directory.  If you want, you can delete them when you're done, with
`rm fifo1 fifo2'.

The second, multi-line command really consists of three separate compound
commands, separated by `&', so they run in parallel.

The first line uses `tee' to send output from command2 into the pipeline
"command3 | command4 >file1", as well as into the `files' fifo1 and fifo2.

The second line causes command5 to read from fifo1, which is really a copy of
the output from command2, and pipes command5's output through command6 into
file2.

Similarly, the third line causes command7 to read from fifo2, which is another
copy of the output from command2, and pipes command7's output through command8
into file3.

Good luck.

--
David Zelinsky
[EMAIL PROTECTED]


Re: bash scripting

1999-02-09 Thread Ralph Winslow
When Eugene Sevinian wrote, I replied:
> 
> Hi, ppl,
> I would like to know, is it possible to fork the standard stdout
> of some command into another two or three pipelines.

Do a 'man tee' to check out the tee command.  It may or may not
supply what you're looking for.  You example below wasn't too clear 
to me.

> The idea is to avoid
> unnecessary disk load during temporary file writing/reading. So I need
> something like this:
> 
> command1 | command2 | command3 | command4 > file1
>  \->command5 | command6 > file2
>   \->command7 | command8 > file3
> 
> Does bash allow such things?
> TIA,
> Eugene Sevinian
> 
> 
> CRD, YerPhI, 375036, Armenia
> URL: http://crdlx5.yerphi.am/
> Phone: 374-2-344873
> 
> --
> Unsubscribe?  mail -s unsubscribe [EMAIL PROTECTED] < /dev/null

-- 
-
Ralph Winslow [EMAIL PROTECTED]
The IQ of the group is that of the member
whose IQ is lowest  divided by the number
of members.