Register
It is currently Wed Oct 22, 2014 8:21 pm

Bash Pitfalls.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 3 posts ] 
Author Message
 PostPosted: Sat Apr 02, 2011 8:21 pm   

Joined: Mon Mar 28, 2011 7:22 am
Posts: 5
Exactly on topic. Check it out! ( Just a wiki with a bunch of examples )


This page shows common errors that Bash programmers make. The following examples are all flawed in some way:

http://mywiki.wooledge.org/BashPitfalls


examples shown:

Contents
for i in $(ls *.mp3)
cp $file $target
Filenames with leading dashes
[ $foo = "bar" ]
cd $(dirname "$f")
[ "$foo" = bar && "$bar" = foo ]
[[ $foo > 7 ]]
grep foo bar | while read -r; do ((count++)); done
if [grep foo myfile]
if [bar="$foo"]
if [ [ a = b ] && [ c = d ] ]
read $foo
cat file | sed s/foo/bar/ > file
echo $foo
$foo=bar
foo = bar
echo <<EOF
su -c 'some command'
cd /foo; bar
[ bar == "$foo" ]
for i in {1..10}; do ./something &; done
cmd1 && cmd2 || cmd3
echo "Hello World!"
for arg in $*
function foo()
echo "~"
local varname=$(command)
sed 's/$foo/good bye/'
tr [A-Z] [a-z]
ps ax | grep gedit
printf "$foo"
for i in {1..$n}
if [[ $foo = $bar ]] (depending on intent)
if [[ $foo =~ 'some RE' ]]
[ -n $foo ] or [ -z $foo ]
[[ -e "$broken_symlink" ]] returns 1 even though $broken_symlink exists
ed file <<<"g/d\{0,3\}/s//e/g" fails
expr sub-string fails for "match"
On UTF-8 and Byte-Order Marks (BOM)
$() removes trailing newlines


Top
 Profile  
 PostPosted: Sun Apr 03, 2011 4:04 am   
User avatar

Joined: Sun Jun 27, 2010 12:57 am
Posts: 192
A very nice find indeed. The author seems to know what he's talking about. And a lot has to do with proper quoting.
Thanks for sharing!


Top
 Profile  
 PostPosted: Thu Apr 07, 2011 9:56 pm   

Joined: Mon May 31, 2010 7:40 pm
Posts: 25
I appreciate this also.


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 7 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP