]
No problem here in 3.2, 4.0 or 4.1
--
Chris F.A. Johnson http://cfajohnson.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU
suitable location.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell
of the variable.
Of the three, local is the only command I use. It says exactly what
it does.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution
On Fri, 11 Dec 2009, Sven Mascheck wrote:
...
comp.unix.shell might match well here and could be entertaining -
IMHO worth to migrate; objections?
This has been discussed more than once in c.u.s; check the
archives.
--
Chris F.A. Johnson, webmaster http://woodbine
On Fri, 11 Dec 2009, Antonio Macchi wrote:
is_file()
{
[ -f $1 ] return
return 1
}
is_file /path/to/dir/* || echo empty
you don't need to check more than the first element
You may need to; it depends on the statement of the problem.
--
Chris F.A. Johnson
-0
All of a sudden, x is not set (or set to the wrong value). So it
should be the *first* command, not the last, that is executed in
the calling shell.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
.
1:2
.
This works with the output of commands, too:
IFS=- read year month day .
$(date +%Y-%m-%d)
.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
===
Author:
Shell Scripting Recipes: A Problem
On Mon, 30 Nov 2009, Lhunath (Maarten B.) wrote:
On 30 Nov 2009, at 15:56, Chris F.A. Johnson wrote:
On Mon, 30 Nov 2009, Greg Wooledge wrote:
On Mon, Nov 30, 2009 at 11:46:03AM +0100, Lhunath (Maarten B.) wrote:
Don't use pipelines to send streams to read. Use file redirection
an error I just append || true to the corresponding
command.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash
POSIX and without a loop by using an
intermediate variable:
foo=00081
bar=${foo%%[!0]*}
foo=${foo#$bar}}
Or even without an intermediate variable:
foo=${foo#${foo%%[!0]*}}
(Though I prefer the variable for legibility.)
--
Chris F.A. Johnson, webmaster http://woodbine
:
printf -v IFS \n
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
Pro Bash Programming: Scripting the GNU/Linux Shell
no functions at all.
Had. Only before 1984. Since then it has had functions.
The first shell I used, the Bourne shell on ATT SVR3.2, had
functions.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
' ' -f1 programs) -y
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
:1} = ( ]#-a ${basePic:4:1} = ) ]
then
echo Got brackets
fi
if [ ${basePic:0:1} = '\(' ] #-a ${basePic:4:1} = '\)' ]
then
echo Got brackets
fi
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
but that just seems stupid
That's a perfectly good way of doing it, but you will want to turn
off filename expansion if there's a chance that the value may
contain wildcards:
set -f
Counter $IDs
set +f
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
the argument
to -W on $IFS _and_ whitespace. Or am I missing something?
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
in a variable does not
handle quotes.
Repeat-By:
~$ declare -a samplearray
~$ samplearray=( x y 'z k')
~$ echo ${samplearray[2]}
z k
~$ samplestring=x y 'z k'
~$ samplearray=( $samplestring )
eval samplearray=( $samplestring )
~$ echo ${samplearray[2]}
'z
--
Chris F.A. Johnson
are you getting the value 'lastmo' from?
If from 'something like date +%m', maybe you could strip off the leading
zero? I.e.:
lastmo=$(echo $lastmo|sed -r 's/0+([0-9])/\1/')
Surely you mean:
lastmo=${lastmo#0}
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
On Tue, 1 Sep 2009, ken wrote:
Doing very simple math in bash fails if a number begins with a zero (0).
Numbers beginning with 0 are base 8 (octal). 08 and 09 are not
valid octal numbers.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
a patch for it? It's not fixed with the patches posted so far.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
, they
are empty. They do pick up the characters if I change delay to
.0001.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach
, and playing around with them has not
helped. Does anyone have a way out of this?
Take a look at the arguments you are actually using:
printf %s\n ${cc[1]}
Use eval:
for e in 0 1 2
do
eval ${cc[$e]}
done
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
On Wed, 29 Jul 2009, mk27 wrote:
Take a look at the arguments you are actually using:
[root~] printf %s ${cc[1]}
bash-ctimels-l
Again, I can't see the missing
Try using the code I posted:
printf %s\n ${cc[1]}
--
Chris F.A. Johnson, webmaster http://woodbine
What is the algorithm for order of expansion of associative arrays?
Single-letter subscripts are expanded alphabetically, but longer
subscripts are not.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
or aliases.
The command to use is 'type'. With the -a option, it will tell
you all of the possible commands that use the name. If you have a
command, a function and an alias with the same name, it will list
all three.
--
Chris F.A. Johnson, webmaster http://woodbine
On Wed, 22 Jul 2009, Marc Herbert wrote:
It seems polling using read -t 0 is not supported.
It is supported in bash 4.0.
--
Chris F.A. Johnson http://cfaj.freeshell.org
===
Author:
Shell
file. What am I doing wrong?
Thanks,
-Alex
--
Chris F.A. Johnson http://cfaj.freeshell.org
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
On Mon, 20 Jul 2009, Pierre Gaston wrote:
On Mon, Jul 20, 2009 at 5:46 AM, Chris F.A. Johnson c...@freeshell.orgwrote:
On Sun, 19 Jul 2009, Chet Ramey wrote:
Chris F.A. Johnson wrote:
mapfile callback code is executed in a subshell.
It's not. It's executed in the same context
On Sun, 19 Jul 2009, Chet Ramey wrote:
Chris F.A. Johnson wrote:
mapfile callback code is executed in a subshell.
It's not. It's executed in the same context as an `eval' or a trap
command.
So it is. Great! I wonder what I was doing wrong before.
--
Chris F.A. Johnson
mapfile callback code is executed in a subshell.
Would it be possible to make it execute in the current shell?
With mapfile -c1, this would make it possible to work on a file without an
explicit loop, making it much faster.
--
Chris F.A. Johnson http
X=a$'\n'b cwill do it, but that is really really
ugly.
X=$'a\nb c'
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005
-quotes, may I
request this as a functionality change?
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
time consumed by pipeline's execution.
times - Display process times.
read - Read a line from the standard input and split it into fields.
readarray - Read lines from a file into an array variable.
readonly - Mark shell variables as unchangeable.
--
Chris F.A. Johnson, webmaster http
.
This isn't a bug; that's where readline thinks the cursor is.
Why would it think that? It's wrong.
If you want to use a prompt, use `read -p'.
I like to write portable scripts; read -p is not portable.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
This is nothing new; it happens in all versions of bash:
printf Enter something:
read -e whatever
Press a key, then cursor left (or ^A); the cursor moves to the
beginning of the line, over E instead of over the character just
entered.
--
Chris F.A. Johnson, webmaster http
On Sat, 16 May 2009, Pierre Gaston wrote:
On Sat, May 16, 2009 at 2:44 AM, Chris F.A. Johnson c...@freeshell.org
wrote:
Am I missing something, or are these extended globbing patterns
equivalent to a plain asterisk?
?(pattern-list) Matches zero or one occurrence of the given
Am I missing something, or are these extended globbing patterns
equivalent to a plain asterisk?
?(pattern-list) Matches zero or one occurrence of the given patterns
*(pattern-list) Matches zero or more occurrences of the given patterns
--
Chris F.A. Johnson, webmaster http
parameters are my two integer arguments,
but I'd like them to be optional. The size of the array is not fixed.
func()
{
local f_array
eval f_array=( \\${...@]}\ )
printf %s\n ${f_arr...@]}
}
a=( qw er ty ui op )
func a
--
Chris F.A. Johnson, webmaster http://woodbine
fail!
http://mywiki.wooledge.org/BashFAQ/005
How can I use array variables?
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
= Do not reply to the From: address; use Reply-To:
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005
archive at Nabble.com.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
= Do not reply to the From: address; use Reply-To:
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
numbers. 08 and 08 ar enot valid octal numbers.
for i in 0{1..9} 10; do printf %02d\n $[i#0};done
Or:
printf %02d\n {1..10}
Or, in bash4.0:
printf %s\n {01..10}
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
= Do not reply to the From: address
to be annoying.
Use a function, e.g.:
p()
{
pp=$( type -p $@ )
}
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
= Do not reply to the From: address; use Reply-To:
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
On Thu, 2 Apr 2009, Mike Coleman wrote:
On Thu, Apr 2, 2009 at 11:33 AM, Chris F.A. Johnson c...@freeshell.org wrote:
On Thu, 2 Apr 2009, Mike Coleman wrote:
[Oops--I sent that incomplete.]
It would be nice if there was some really brief syntax for
$(type -p somecommand)
I find myself
by mapfile? Time the mapfile command and
the loop separately:
time mapfile file
time for i in ${mapfi...@]}
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
===
Author:
Shell Scripting Recipes
(sed -e 's/^ *//' -e 's/ *$//' file)
Chet, how about an option to mapfile that strips leading and/or
trailing spaces?
Another useful option would be to remove newlines.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
= Do not reply to the From: address
=$(( $n + 1 ))
done
printf %s\n ${arra...@]}
echo
printf %s\n ${arra...@]}
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
= Do not reply to the From: address; use Reply-To:
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
\n $1 $2
done
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
= Do not reply to the From: address; use Reply-To:
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
I would like to see read's -d option expanded to accept a string of
characters, any one of which would terminate input. The character
which terminates input should be stored in a variable, e.g.,
$REPLY_END.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
...Aborted
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
it.
--
Chris F.A. Johnson, webmaster http://woodbine-gerrard.com
= Do not reply to the From: address; use Reply-To:
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
In bash4.0, the terminal is not reset if this is times out:
read -st1
--
Chris F.A. Johnson, webmaster http://Woodbine-Gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
(for Tesst then), but for all s, of course.
man bash4:
... the ^ and , expansions match and convert only the first
character.
--
Chris F.A. Johnson, webmaster http://Woodbine-Gerrard.com
===
Author
-- 1 root root 0 Nov 20 12:22 xA
# ls -l x[A-Z]
-rw-r--r-- 1 root root 0 Nov 20 12:22 xA
Any ideas?
You are using a locale that conflates upper- and lowercase as
aAbBcC...yYzZ.
Try it with: export LC_ALL=C
--
Chris F.A. Johnson, webmaster http://Woodbine-Gerrard.com
-
)
--
Chris F.A. Johnson, webmaster http://Woodbine-Gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
unset my_array[0]
echo Array [EMAIL PROTECTED]
shopt -s nullglob
# remove first entry
unset my_array[0]
There is no longer any my_array[0] to unset. Try:
unset my_array[1]
echo Array [EMAIL PROTECTED]
--
Chris F.A. Johnson, webmaster http
in *
do
chg=$( echo $f | sed 's:(www.somewhere.net)::' )
mv $f $chg
done
--
Chris F.A. Johnson, webmaster http://Woodbine-Gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005
%\?}
done
--
Chris F.A. Johnson, webmaster http://Woodbine-Gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
F.A. Johnson, webmaster http://Woodbine-Gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
}
--
Chris F.A. Johnson, webmaster http://Woodbine-Gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
) seems to fix
the problem:
Unfortunately, this violates Posix and traditional sh behavior.
If you want fully sh-compatible behavior, you have to turn off history
expansion (set +o history).
I find it adequate to set histchars to an empty string.
--
Chris F.A. Johnson, webmaster
On 2008-07-08, Richard Neill wrote:
Dear All,
When using read, it would be really neat to be able to pre-fill the form
with a default (or previous) value.
For example, a script which wants you to enter your name, and thinks
that my name is Richard, but that I might want to correct it.
, it appears to be very
slow compared to $(file). Any thoughts?
var=$( cat file; echo . )
var=${var%.}
--
Chris F.A. Johnson, webmaster http://Woodbine-Gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution
.
--
Chris F.A. Johnson, webmaster http://Woodbine-Gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
.
On 2008-03-28, Eric Blake wrote:
Chris F.A. Johnson cfajohnson at gmail.com writes:
You can find a shell function to replace the external basename
command at: http://cfaj.freeshell.org/shell/scripts/basename-sh.
Except that your example is not POSIX-compliant. POSIX requires
command at: http://cfaj.freeshell.org/shell/scripts/basename-sh.
--
Chris F.A. Johnson, webmaster http://Woodbine-Gerrard.com
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
.
about it? Would it be a difficult task?
It is more likely to be the command substitution that is slow.
--
Chris F.A. Johnson, webmaster http://Woodbine-Gerrard.com
===
Author:
Shell Scripting Recipes
people think of this?
I wouldn't use that method to populate an array.
echo 0 1 2^3 4 5^6 7 8 |
{
read line
IFS=^
array=( $line )
printf %s\n [EMAIL PROTECTED]
}
--
Chris F.A. Johnson, webmaster http://Woodbine-Gerrard.com
this whitespace get automatically truncated
from $line, and i dont want that..i want the whole line to go into
outfile, no matter if the last characters are whitespace!
while IFS= read -r line
do
printf %s\n $line
done infile
--
Chris F.A. Johnson, webmaster http://Woodbine
?
--
Chris F.A. Johnson http://cfaj.freeshell.org
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
.
... should I use su - ?
If you use su -, it does the equivalent of logging in, and thus
reads .bash_profile; su by itself doesn't.
--
Chris F.A. Johnson http://cfaj.freeshell.org
===
Author:
Shell
'
$svnRoot/$projectName
$'\r'
CONFIRM
...
yes | trac-admin $tracRoot/$projectName initenv
--
Chris F.A. Johnson http://cfaj.freeshell.org
===
Author:
Shell Scripting Recipes: A Problem-Solution
Press up arrow to edit \$default\: XX
--
Chris F.A. Johnson http://cfaj.freeshell.org
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress
Not sure how to do it. I have been looking around and saw
things like getopts, but I am only passing in one variable and thought it
should be fairly simple
whois $1 | grep ...
--
Chris F.A. Johnson http://cfaj.freeshell.org
--
Chris F.A. Johnson http://cfaj.freeshell.org
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
___
Bug-bash mailing list
Bug-bash
?
--
Chris F.A. Johnson http://cfaj.freeshell.org
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
___
Bug-bash mailing list
Bug-bash
+X ] || echo hello
--
Chris F.A. Johnson http://cfaj.freeshell.org
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress)
___
Bug
## shift+down-arrow
You may need to adjust the bindings for your terminal.
--
Chris F.A. Johnson http://cfaj.freeshell.org
===
Author:
Shell Scripting Recipes: A Problem-Solution
$ echo ${foo^^} ## Convert all characters
BAR
$ echo ${foo^[a-m]} ## Convert first character that matches pattern
Bar
$ echo ${foo^^[a-m]} ## Convert all characters that match pattern
BAr
--
Chris F.A. Johnson http://cfaj.freeshell.org
://cfaj.freeshell.org/shell/bash/loadables/. Second, is
William Park's bash extension at:
http://home.eol.ca/~parkw/index.html#bash.
--
Chris F.A. Johnson http://cfaj.freeshell.org
===
Author:
Shell
only
happen when commas or sequence expressions are used, and while the
inner braces used commads, the outer braces did not -mike
Let's see...
a-{b{d,e}}-c
a-{bd,be}-c
a-bd-c a-be-c
It looks okey, I think.
Except that b{d,e} expands to 'bd be', not 'bd,be'.
--
Chris F.A
, the backslash is not considered a
character, it is an escape mechanism.
--
Chris F.A. Johnson http://cfaj.freeshell.org
===
Author:
Shell Scripting Recipes: A Problem-Solution Approach (2005, Apress
ok\c to work.
The older bash-3.00.15(3) works with --enable-xpg-echo-default.
So, it is possible to have both the following working in sh and bash
echo -n ok
echo ok\c
printf %s ok
--
Chris F.A. Johnson http://cfaj.freeshell.org
is $FUNCNAME; }
a.b
My name is a.b
unset a.b
-bash: unset: `a.b': not a valid identifier
unset -f a.b
--
Chris F.A. Johnson http://cfaj.freeshell.org
===
Author:
Shell
.
#! /bin/bash
Add:
shopt -s expand_aliases
if true; then
alias myls=ls
alias -p
myls
fi
myls
--
Chris F.A. Johnson http://cfaj.freeshell.org
otherwise.
Thanks.
Duane Ellis
___
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash
--
Chris F.A. Johnson http://cfaj.freeshell.org
.
To see what this command has read:
echo REPLY=$REPLY
echo $b
echo $c
done (ls -al ~/)
exit 0
--
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach
%s\n [EMAIL PROTECTED]
1
0
1
0
--
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
.
--
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
is
naturally going to fail).
--
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
$
--
Chris F.A. Johnson http://cfaj.freeshell.org
==
Shell Scripting Recipes: A Problem-Solution Approach, 2005, Apress
http://www.torfree.net/~chris/books/cfaj/ssr.html
On Thu, 12 May 2005, Tony Jo wrote:
Chris F.A. Johnson [EMAIL PROTECTED] wrote in message
news:[EMAIL PROTECTED]
When quoting parts of a script or error messages, please be
accurate (cut and paste rather than retyping). You used:
temp=`expr $val1 + $val2`
or you wouldn't have received
.
$ uname -a
Linux sergio 2.6.8-2-686 #1 Mon Jan 24 03:58:38 EST 2005 i686 GNU/Linux
What is your locale?
It probably collates in the order 'aAbBcCdD...zZ'.
--
Chris F.A. Johnson http://cfaj.freeshell.org
string of more than one
character.
From the man page:
Positional Parameters
When a positional parameter consisting of more than a single digit is
expanded, it must be enclosed in braces (see EXPANSION below).
--
Chris F.A. Johnson http
101 - 193 of 193 matches
Mail list logo