[nycbug-talk] what are your usefull hacks, the real simple ones

Steven Kreuzer skreuzer at f2o.org
Mon May 8 10:31:11 EDT 2006


Marc Spitzer wrote:
> any other short and quick hacks out there?
>   

I work in a shell that does everything I want with a few exceptions,
such as pushd and popd not being a shell built-in. However, they are
really easy to implement as a shell function:

function pushd {
  dirname=$1
  cd ${dirname:?"Missing directory name."}
  DIRSTACK="$PWD ${DIRSTACK:-$OLDPWD}"
  print "$DIRSTACK"
}

function popd {
  DIRSTACK=${DIRSTACK#* }
  cd ${DIRSTACK%% *}
  print "$PWD"
}


Also, there is a command called seq which is part of the gnu core-utils
which is pretty much just  a program that takes a starting number and
and ending number and outputs all the numbers in between:

$ seq 1 5
1 2 3 4 5

which can be very very handy when doing loops in the shell. I don't have
the core-utils installed, so I don't have seq, but its pretty easy to
implement it as a shell function:

function seq {
  local I=$1
  while [ $2 != $I ]; do
    print -n "$I "
    I=$(( $I + 1 ))
  done;
  print "$2"
}

-----
SK



More information about the talk mailing list