Re: [OT] bash help

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

 



On 02/19/2017 03:46 PM, Patrick O'Callaghan wrote:
On Sun, 2017-02-19 at 05:22 -0800, Mike Wright wrote:
Hi all,

My brain cell ran away from home.  I have an incredibly simple script
that doesn't do what I expect.  I use "mkdir DIR; cd DIR" a lot so I'm
trying to put it in a script: "~/bin/mdcd".

After checking that $1 exists:

dir="$1"
mkdir -p "$dir"
cd "$dir"   <------ never executes

The directory is created so there is no error there.

Huh? Insight anyone?

If it's a Shell script then it's executing in a sub-shell, which then
terminates, so the current directory of the calling Shell is unchanged.

To get the effect you want either use an alias or call "eval".

To both Robert Nichols & Patrick O'Callaghan,

Got it - after resolving a "gotcha". I'm executing this on a machine I shelled into. But after executing the alias mkcd=". /home/mike/bin/mdcd" the path is created but I'm bounced all the back to my local machine!!!

Turns out the script ended with "exit 0" which apparently is executed in the context of the calling bash and logs me out.

Thanks for the help


_______________________________________________
users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx



[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux