Shell dump

One-liner for deleting multiple lines

With thanks to the debian-user-german mailing-list:

perl -0777  -i.bak -pe 's/###START###.*###ENDE###\s//sm' file
perl -i -ne 'next if /^###START###$/../^###END###$/; print' file
sed -n '/START/,/END/p' file
sed -i '/START/,/END/d' file

Expanding and globbing

Shells are a strange thing…look at this example:

$ bash -c "if [ -e /tmp/* ] ; then echo 'YES' ; fi"
bash: line 0: [: too many arguments

Sounds logical, because bash expands the *, but…

$ zsh -c "if [ -e /tmp/* ] ; then echo 'YES' ; fi"
YES

I would have expected that zsh would do the same as bash, especially because zsh is otherwise expanding everything.

How to find the absolute path of a shell script

This is my solution, any hints for a better way, please mail me!

#!/bin/bash

PWD=$(pwd)
DIR=$0
ABS=${DIR}
if ! [ "${DIR:0:1}" == "/" ] ; then
        ABS=${PWD}/${DIR}
fi
echo ${ABS}
ls ${ABS}
linux/shell_dump.txt · Last modified: 2008/10/09 14:17 (external edit)
GNU Free Documentation License 1.2
chimeric.de = chi`s home Creative Commons License Valid CSS Driven by DokuWiki do yourself a favour and use a real browser - get firefox!! Recent changes RSS feed Valid XHTML 1.0