[Slackbuilds-users] pushd on /bin/sh scripts

Robby Workman rworkman at slackbuilds.org
Thu Feb 22 03:58:12 UTC 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Lehman Black wrote:
> The following SlackBuilds have pushd/popd in them and have their shell type
> incorrectly labeled as /bin/sh.


Yes, we discussed that on the development list.

This one is *all* my fault - it had never occurred to me that
pushd/popd was bash-only until it came up in conversation on
an unrelated topic.  Those will be corrected as soon as possible.

I *think* the consensus we reached was that bash-isms are strongly
discouraged, but if there's simply no good way around it, make sure
the script has #!/bin/bash instead of #!/bin/sh.


As an aside, the primary (only?) reason for using pushd/popd instead
of subshells was concerns with error checking.  To explain:

$ ls /test
file1 file2 file3
$ cd /test
$ ls file4 || exit1
[shell exits since file4 is not found]

$ ( ls file4 || exit 1 )
In this case, the subshell exits, but since it was a subshell, it
does not affect the calling shell.  In a SlackBuild script, it is
often desirable to bail out of the entire script if one of the
subshells errors out.  Some ways to do it have already been addressed
in the archives.

For our purposes, the use of this:

  cd /somedir
    do_something()
  cd -

should accomplish what we want if a subshell is not desirable.

Anyway, thanks for the report - especially the nice list of
affected scripts  :)

RW

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.2 (GNU/Linux)

iD8DBQFF3RTU7QPvQNDlLwQRAthZAJ9+oHkpivhcq9liqHyy8wOGqdYQZwCaA/a4
c2Hanbi5C+oshMW6Gcny/p8=
=cbFN
-----END PGP SIGNATURE-----



More information about the Slackbuilds-users mailing list