high wisdom



Tue Feb 24 12:50:38 IST 2009

Shell-fu

A few shell tricks that I picked up.
Variable manipulation:
gera@gera-laptop:~$ BAR=bar
gera@gera-laptop:~$ echo $FOO

gera@gera-laptop:~$ echo $BAR
bar
gera@gera-laptop:~$ echo ${FOO:-baz}
baz
gera@gera-laptop:~$ echo $FOO

gera@gera-laptop:~$ echo ${FOO:-$BAR}
bar
gera@gera-laptop:~$ echo $FOO

gera@gera-laptop:~$ echo ${FOO:=newvalue}
newvalue
gera@gera-laptop:~$ echo $FOO
newvalue
gera@gera-laptop:~$ echo ${BAR:=newvalue}
bar
gera@gera-laptop:~$ echo $BAR
bar
More here.

Here strings - which are like here docs.
gera@gera-laptop:~$ cat <<END
> foo
> bar
> baz spam eggs
> END
foo
bar
baz spam eggs
gera@gera-laptop:~$ cat <<<"foo bar baz spam eggs"
foo bar baz spam eggs
Although you can do the same with a piped echo, the here string saves you a process (the echo). Still, I'm looking for a more convincing use case.
gera@gera-laptop:~$ echo "foo bar baz spam eggs" | cat
foo bar baz spam eggs

Posted by gera | Permanent link | [ hide comments ]
Add comment here
name:
e-mail:
website:
spam-protection, please enter code: captcha, sorry
comment:

remember me
request e-mail if someone adds comments
Your e-Mail will not be published,
http://www.URL.com will turn to link automatically,
html is not permitted