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

Scott J. Harmon harmon at ksu.edu
Thu Feb 22 04:59:03 UTC 2007


Robby Workman wrote:
> -----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.
>   
When I use subshells in a script I usually test the return value with 
$?...alternatively you could do something like:

( ls file4 || exit 1 ) || exit 1


(SNIP)
>
> RW
>
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v2.0.2 (GNU/Linux)
>
> iD8DBQFF3RTU7QPvQNDlLwQRAthZAJ9+oHkpivhcq9liqHyy8wOGqdYQZwCaA/a4
> c2Hanbi5C+oshMW6Gcny/p8=
> =cbFN
> -----END PGP SIGNATURE-----
> _______________________________________________
> Slackbuilds-users mailing list
> Slackbuilds-users at slackbuilds.org
> http://lists.slackbuilds.org/mailman/listinfo/slackbuilds-users
>   
Scott.

-- 
"Computer Science is no more about computers than astronomy is about telescopes." - Edsger Dijkstra




More information about the Slackbuilds-users mailing list