The results were moved into mcd.sh, with compatibility with Dash.
I went through a whole lot of hell to try to figure out how to make and change into a directory. My simple 4DOS mini-script wasn't properly translating to Bash, and I didn't understand why. So I posted this:
I'm trying to create a simple script to md
+ cd
into a directory.
It's much more difficult than I expect.
First, I learn that I can't do something trivial like this.
cat > ~/script.sh md $1 cd $1 # press control-d chmod +x script.sh ~/script.sh
.. but this I already knew. I tried working with an alias, but I can't figure out how to use $1
twice or how to spit out two commands with one alias.
i.e. this stuff won't work:
alias mcd='md $1 ; cd $1' alias mcd='md {$1} ; cd {$1}'
but even if I do this:
alias mcd='echo $1 ; echo $1'
then $1
is only usable once.
mcd testing # => testing
Then I tried to step back and have my md
+cd
in a script.
I make a script which spits out the commands, like this:
cat > ~/mcd.sh echo md $1 echo cd $1 # press control-d chmod +x script.sh
and then I make an alias like this:
alias mcd='eval $(~/mcd.sh)'
and I run it like:
mcd testing
but this will only evaluate the first expression in ~/script.sh
which makes the testing directory (but does not cd
into it)
I guess my question is:
How can I make an alias do two things?
The answer?
Either:
mcd() { mkdir "$1" cd "$1" }
or:
mcd() { mkdir "$1" ; cd "$1" ; }
Last updated 2019-11-20 at 18:09:08
ported
ported
(even though this is obscure)