Ben Love on 1 Oct 2009 15:05:42 -0700 |
> I have to write some POSIX shell scripts (actually, they need run > under busybox sh in TinyCoreLinux) and I have learned to love pushd > and popd in my scripts. Any suggestions on the best way to achieve > the same effect? Thanks in advance. # There is a newline in that string after $PWD. alias pushd='DIRS="$PWD $DIRS"; cd' # This is all one line. alias popd='LINE=`echo "\$DIRS" | sed -ne '1p'`;[ "$LINE" != "" ] && cd $LINE;DIRS=`echo "\$DIRS" | sed -e '1d'`' This is newline separated, which works for everything by directories with newlines in them. Tell your users not to do that. That's worse than spaces in directory names! :-) It works on bash (of course), and I tested it on busybox sh, which claimed it was ash on my system. Oh, and be careful that $DIRS is not used for something else. Maybe a better name could be used. Ben -- Ben Love blove+signature (at) kylimar.com || ASCII ribbon campaign - () http://www.kylimar.com/ || against HTML e-mail - /\ Attachment:
signature.asc ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|