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