This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
echo ' ${var-_} ${var:-_} $var ${!var[@]}' | |
test_all() | |
{ | |
test "${var-_}" && echo -n 'T ' || echo -n 'F ' | |
test "${var:-_}" && echo -n 'T ' || echo -n 'F ' | |
test "$var" && echo -n 'T ' || echo -n 'F ' | |
[[ "${!var[@]}" ]] && echo 'T' || echo 'F' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# by Dennis Williamson | |
# 2010-10-06, revised 2010-11-10 | |
# for http://stackoverflow.com/questions/3869072/test-for-non-zero-length-string-in-bash-n-var-or-var | |
# designed to fit an 80 character terminal | |
dw=5 # description column width | |
w=6 # table column width | |
t () { printf "%-${w}s" "true"; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tar -X <(cat /etc/fstab | cut -d ' ' -f 2 | grep ^$dir) -zcvf dir.tar.gz $dir/* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Filenames can contain *any* character except only null (\0) and slash (/); | |
# here's some general rules to handle them: | |
# | |
# $'...' can be used to create human readable strings with escape sequences. | |
# | |
# ' -- ' in commands is necessary to separate arguments from filenames, since | |
# filenames can start with '--', and would therefore be handled as parameters. | |
# To handle parameters properly (like GNU tools) use `getopt`. | |
# |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This works even with really weird filenames like $'--$`\! *@ \a\b\e\E\f\n\r\t\v\\\"\' ' | |
file_count() | |
{ | |
if [ ! -e "$1" ] | |
then | |
exit 1 | |
fi | |
local -i files=$(find "$(readlink -f -- "$1")" -type f -print0 | grep -cz -- -) | |
echo $files |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Can be used to for example count the number of files returned by `find ... -print0` | |
grep -cz . -- - |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
grep -v '^\(none\|rootfs\)' /proc/mounts > /etc/mtab |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
command | tee /dev/fd/2 | |
# Can be used to debug variable computations - Just plonk the tee at the end: | |
# $ uid=$(id -u | tee /dev/fd/2) | |
# 1234 | |
# $ echo $uid | |
# 1234 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
while true | |
do | |
inotifywait -e modify,attrib,move,delete . | |
make test | |
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find . -maxdepth 1 -print0 | \ | |
sort --zero-terminated | \ | |
while IFS= read -rd $'\0' path | |
do | |
grep "$(basename -- "${path:2}")" -- Makefile >/dev/null || echo "Could not find $path" | |
done |
OlderNewer