On Mon, Feb 20, 2017 at 10:46:23AM +0000, Andy Blanchard wrote: > On 20 February 2017 at 09:18, T_POL <t_pol@xxxxxxxxxx> wrote: > > > > not sure about that but I think the "cd" command executes indeed > > but it's valid only for the scripts' environment and not for the > > shell you started the script from. > > *ding* *ding* *ding* We have a winner! > > Shells execute in their own instance of bash (or whatever) - a > subshell. The way to do this is with an alias or function, depending > on your needs (aliases don't except parameters, functions do), so > here's the function for "mdcd": > > $ mdcd() { > # additional checks here, per original post > mkdir $1 > cd $1 > } > > > Alternatively, you can force a script to run in the current shell by sourcing it > > $ . {scriptname} > > Note the "." between the prompt and script (you can also use the more > literal "source"): > > $ source {scriptname} > > Another option, just for completeness, would be to alias sourcing a > script, e.g.: > > $ alias mdcd='. {path to script}' > A caveat I think the OP already found out. Both the sourced script and the function would be running in the users interactive shell environment, it must for the cd to be effective. Thus you do not want to "exit" from either the sourced script nor from the function as that causes the interactive shell to exit. In the function you can use "return <status>" instead of "exit <status>". Jon -- Jon H. LaBadie jonfu@xxxxxxxxxx _______________________________________________ users mailing list -- users@xxxxxxxxxxxxxxxxxxxxxxx To unsubscribe send an email to users-leave@xxxxxxxxxxxxxxxxxxxxxxx