|
From: Gary Williamson on 19 Jun 2008 01:28 In a shell script I coded: printf "padded=%02d:%02d:%02d\n", $hour,$minute,$sec With the following values: $hour=0 $minute=7 $sec=26 However when I run the script I get an error: /usr/local/gary/bin/myscript: line 37: printf: 0,7,26: invalid number time=00:00:00 Why? Gary
From: Bill Marcum on 19 Jun 2008 02:23 On 2008-06-19, Gary Williamson <garywill(a)usca.edu> wrote: > In a shell script I coded: > > printf "padded=%02d:%02d:%02d\n", $hour,$minute,$sec > > With the following values: > $hour=0 > $minute=7 > $sec=26 > > However when I run the script I get an error: > > /usr/local/gary/bin/myscript: line 37: printf: 0,7,26: invalid number > time=00:00:00 > > Why? > Use spaces, not commas, between arguments in a shell script. printf "padded=%02d:%02d:%02d\n" $hour $minute $sec
From: Stephane CHAZELAS on 19 Jun 2008 03:04 2008-06-19, 08:23(+02), Bill Marcum: [...] > Use spaces, not commas, between arguments in a shell script. > > printf "padded=%02d:%02d:%02d\n" $hour $minute $sec printf "padded=%02d:%02d:%02d\n" "$hour" "$minute" "$sec" remember that leaving a variable unquoted has a very special meaning to the shell. -- St�phane
|
Pages: 1 Prev: multiple substitutions with sed Next: How To Debug a Running Shell Script |