Invoking pushd in a shell manuscript

I have a straightforward manuscript that I intend to invoke 'pressed' adhered to by an additional command. Yet the 'pushd' command inside the manuscript does not appear to stick past the manuscript.

What is a means to make this execute in the shell terminal?


pushd $1

What I actually intend to complete is invoke pushd adhered to by other-command with one command.

2019-05-13 04:36:37
Source Share
Answers: 2

A shell manuscript generally implements in a different instance of the shell program, /bin/sh in this instance. Your pushd command influences that below - shell is functioning directory site just. If it were or else, any kind of program you ranged from the shell can tinker your shell is functioning directory site.

To execute that manuscript within the existing shell, claim this rather:

$ . my-command somedir

or, extra verbosely:

$ source my-command somedir

To make it show up that your program functions like any kind of various other, you can make use of a pen names:

$ alias mycmd='source my-command'
$ mycmd /bin
$ pwd
2019-05-17 18:31:47

Scripts can not modify their moms and dad processe is setting. As a result of this, any kind of setting adjustments made in the manuscript are shed.

To run the manuscript in the very same procedure, you can 'resource' the manuscript similar to this

. /path/to/ args
2019-05-17 18:31:01