Tag Archive for Bash

Execute multiple commands in background and evaluate their return codes

#!/bin/bash
/bin/false &
PID1=$!
/bin/true &
PID2=$!
wait $PID1
RET1=$?
wait $PID2
RET2=$?
if [ $RET1 == 0 ] && [ $RET2 == 0 ]; then
echo succeeded
exit 0
else
echo failed
exit 1
fi

source

Determine the change in file size in lines between Subversion revisions

svn diff -rREV1:REV2|grep "^(-|+)"|cut -b1|sort -r|
uniq -c|tr -d ' 12'|tr '+-' '- 12'|sed 's/ //g'|bc

source

Automatically remove all nonexsiting files in the current dir from svn

#!/bin/bash

if [ ! "$1" ]
then
1='.'
fi

svn rm $1 `svn st $1 | grep '^!.*' | tr -d '! ' | tr '
' ' ' | sort -n`

source

Automatically add all new files in the current dir.

#!/bin/bash

if [ ! "$1" ]
then
1='.'
fi

echo "Processing $1"
svn add $1 `svn st $1 | grep '^?.*' | tr -d '? ' | sort -n | tr '
' ' '`

source

bash/sh handling of unclosed quotes

bourne shells silently insert an unbalanced single, double or back quote at EOF (including here-documents)

source

Bash functions for running rails unit and functional tests

# simple wrappers for running unit and functional tests in rails apps
# INSTEAD OF : ruby test/unit/user_test.rb
# DO THIS : test_unit user
test_unit () {
if [[ -n "$1" ]]; then
ruby test/unit/$1_test.rb;
else
"USAGE : test_unit [name_of_test]"
fi
}

# INSTEAD OF : ruby test/functional/users_controller_test.rb
# DO THIS : test_func user
test_func () {
if [[ -n "$1" ]]; then
ruby test/functional/$1_controller_test.rb;
else
"USAGE : test_func [name_of_test]"
fi
}

source

Find possible plist-Files for an given Application

mdfind 'kMDItemFSName == "*textmate*"cw' | grep ".plist$"

source

OsX position your Dock on top

Dock Top
defaults write com.apple.Dock orientation top

Dock Right
defaults write com.apple.dock pinning end

source

Os X Make Hidden Files Obvious on the Dock

Make Hidden Files Apparent
defaults write com.apple.Dock showhidden -bool yes

Make Hidden Files Unapparent
defaults write com.apple.Dock showhidden -bool no

source

Append Line to a File

echo "<string to append>" >> <file>

#Example:

echo "My string" >> /home/user/myfile.txt

source