Re: [OT] bash help

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

 



On 02/19/2017 07:22 AM, 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 script runs in a child process. It changes its _own_ working directory and then exits, leaving the parent shell exactly where it was before. Scripts like that need to be _sourced_, not simply executed. It probably makes sense to set up an alias to do that:

    alias mkdirp=". mkdirp.sh"

Then you can type "mkdirp /wherever/whatever" and it will run ". mkdirp.sh /wherever/whatever".

--
Bob Nichols     "NOSPAM" is really part of my email address.
                Do NOT delete it.
_______________________________________________
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