Comments on: Bash parameter expansion cheatsheet http://www.xaprb.com/blog/2007/03/29/bash-parameter-expansion-cheatsheet/ Stay curious! Fri, 10 May 2013 18:25:19 +0000 hourly 1 http://wordpress.org/?v=3.5.1 By: Dave Eddy http://www.xaprb.com/blog/2007/03/29/bash-parameter-expansion-cheatsheet/#comment-20077 Dave Eddy Mon, 04 Jun 2012 18:39:43 +0000 http://www.xaprb.com/blog/?p=316#comment-20077 You can break a lot of stuff if you don’t quote your expansions.

http://mywiki.wooledge.org/BashGuide/Parameters#Parameter_Expansion

]]>
By: find command in unix http://www.xaprb.com/blog/2007/03/29/bash-parameter-expansion-cheatsheet/#comment-19457 find command in unix Mon, 27 Jun 2011 08:13:20 +0000 http://www.xaprb.com/blog/?p=316#comment-19457 Important point to note is that $* and $@ bash parameters behave identical without double quotes but entirely different if used within double quotes. in case of $* individual parameters will be separated by IFS characters while in case of $@ individual parameters will appear in quotes and separated by space.

]]>
By: Keith T http://www.xaprb.com/blog/2007/03/29/bash-parameter-expansion-cheatsheet/#comment-19174 Keith T Wed, 23 Feb 2011 18:45:18 +0000 http://www.xaprb.com/blog/?p=316#comment-19174 Using eval and echo you can kludge up nested parameter expansion.

Let’s say you have $param1 and $param2. param1=”Hi” and param2=”There”. You have a routine you want to reuse, wherein all you have to pass it is 1 or 2 and it will use the appropriate $param1 or $param2.

You set INDEX=1 or INDEX=2 depending on which one you want.

> INDEX=1
> echo $(eval echo $(eval ‘echo \$\{param$INDEX\}’))
Hi
> INDEX=2
> echo $(eval echo $(eval ‘echo \$\{param$INDEX\}’))
There

It’s convoluted for sure, but it works.

]]>
By: alex5161 http://www.xaprb.com/blog/2007/03/29/bash-parameter-expansion-cheatsheet/#comment-18991 alex5161 Tue, 21 Dec 2010 00:37:24 +0000 http://www.xaprb.com/blog/?p=316#comment-18991 You have one not completely correct example in the pattern matching:

# Oops, I didn’t mean that… get rid of the numbers.
for file in *.gif; do mv $file ${file##[0-9]}; done

– the ${file##[0-9]} by using ‘##’ should means to remove long matching of number – here that is unappliable:
if $file is ‘a555name’ – nothing matched, as before number there is something else.
if $file is ’123name’ – only first number is matched, while, I guess, assumed to remove ’123′: it is not happend, because [0-9] – is one number only.
To remove ’123′ it could be ${file#*[0-9]} – no needs for ‘##’, as it would remove up to any found number in the file name, if the name has it.
But it is not good enouth, as it, also, would remove ‘a555′ from the ‘a555name’, that is not planned.
It should be specified as ‘any number of diggits from beggining of the variable value’, something like : /^[0-9]+/; but pattern expansion is not accepting such syntax.

]]>
By: [bash] Parameter expansions « *NIX tricks http://www.xaprb.com/blog/2007/03/29/bash-parameter-expansion-cheatsheet/#comment-17084 [bash] Parameter expansions « *NIX tricks Thu, 08 Oct 2009 21:13:21 +0000 http://www.xaprb.com/blog/?p=316#comment-17084 [...] Reference: Directly copied from here. [...]

]]>