JP Vossen on 25 Aug 2011 12:11:14 -0700


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: [PLUG] pushd and popd on debian squeeze


Date: Thu, 25 Aug 2011 14:35:20 -0400
From: Michael Lazin<microlaser@gmail.com>
Subject: [PLUG] pushd and popd on debian squeeze

Hi, I am trying to run a bash script on debian squeeze that uses pushd and
popd.  They are not in the path and when I got to the root directory as root
and type "find -name pushd" nothing comes up.  Why are these missing from
debian?  How can I get them?


> Date: Thu, 25 Aug 2011 14:40:45 -0400
> From: Douglas Muth <doug.muth@gmail.com>
>
> They're shell commands.

True in bash. Note the bash 'help' command, which is *much* more useful than the 'man' command for builtins! See also the 'type -a' command. I thought 'which' was an alias to 'type -a' but at least on Squeeze it isn't. Huh.

[jp@bitbox2:T2:L1:C1:J0:2011-08-25_15:00:21_EDT]
/home/jp$ cat /etc/debian_version
6.0.2

[jp@bitbox2:T2:L1:C2:J0:2011-08-25_15:00:25_EDT]
/home/jp$ help pushd
pushd: pushd [-n] [+N | -N | dir]
    Add directories to stack.
[...]

[jp@bitbox2:T2:L1:C4:J0:2011-08-25_15:01:05_EDT]
/home/jp$ type -a pushd
pushd is a shell builtin


> Make sure your script starts with:
>
> #!/bin/bash
> and NOT:
> #!/bin/sh

It's slightly more secure to use (note trailing -):
	#!/bin/bash -
	or
	#!/bin/sh -

I *think* I talked about that in http://princessleia.com/plug/2009-Secure_Shell_Scripts.pdf.


> While sh is usually symlinked to bash, if it's run as sh, it will
> emulate the Bourne Shell, and bash-specific commands like pushd and
> popd will not be available.

True on Debian, but watch out! That has *not* been true on Ubuntu for a while now, and it *will* get you in to trouble if you assume '/bin/sh' is really sorta-kinda bash. For details see http://princessleia.com/plug/2008-JP_bash_vs_dash.pdf.

Short version: /bin/sh --> dash (*not* bash) on Ubuntu, and dash != bash! Heck, sh != bash != dash, while we're at it. "Portable" shell scripts can be really hard to write, that's partly why Perl exists. :-) (And no, I don't wanna hear about zsh Paul... ;-)

HTH,
JP
----------------------------|:::======|-------------------------------
JP Vossen, CISSP            |:::======|      http://bashcookbook.com/
My Account, My Opinions     |=========|      http://www.jpsdomain.org/
----------------------------|=========|-------------------------------
"Microsoft Tax" = the additional hardware & yearly fees for the add-on
software required to protect Windows from its own poorly designed and
implemented self, while the overhead incidentally flattens Moore's Law.
___________________________________________________________________________
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