-1

I am using tcsh.

I want to create an alias where I cd into another directory and execute a command.

But I dont want to touch cd -. How do i do this?

Thanks in advance.

Edit: PS: The other directory has a script that uses local relative paths, thats why I have to cd into that dir.

justrajdeep
  • 855
  • 3
  • 12
  • 29

3 Answers3

0

Just execute your command in the appropriate directory.

If I am in /home/hardknock/Documents/ and I dont want to leave this directory but I want to delete something in /etc/ I can just sudo rm -r /etc/folder_name/ and I will never have left Documents.

The same logic applies to pretty much any CLI command.

reka18
  • 7,440
  • 5
  • 16
  • 37
0

Because - is an alias to the last directory I was in, you could, rather complicatedly preserve it using the directory history stack:

pushd -
pushd -
cd /
do command here
popd
popd

I'm sure there's a better way of accomplishing this, but this is one way of doing it.

Anya Shenanigans
  • 91,618
  • 3
  • 107
  • 122
0

Run it in subshell!

alias myalias '(cd /to/directory; run_commands)'
uzsolt
  • 5,832
  • 2
  • 20
  • 32