Marginal Hacks: Santas little helper
Wednesday, May 27, 2009 9:28:02 AM
The bash(1) shell has some sadly underestimated features.
Most of shell users are aware of the existence of the so-called "here documents":
But did you know there's also "here string"?
.. or, a bit more practical:
Most of shell users are aware of the existence of the so-called "here documents":
$ # create text file
$ cat > file.txt <<!
My username is $LOGNAME and my "home" directory is $HOME.
The quick brown fox...
!
$ #display the file content
$ cat file.txt
My name is unefunge and my "home" directory is /home/unefunge
The quick brown fox...
$
But did you know there's also "here string"?
$ # let's rot13
$ tr "a-z" "n-za-m" <<<"onfu ebpxf"
bash rocks
$
.. or, a bit more practical:
$ echo $HOME
/export/home/homer
$ BARTS_HOME=$(sed -e 's/homer/bart/' <<< "$HOME")
$ echo $BARTS_HOME
/export/home/bart






