Reputation: 1892
I have write very small script which contain one alias and execute that But it is not executing the command ts. Could anyone please provide me input to fix this issue.
#!/bin/tcsh
alias ts 'cd /path/goswami/;'
ts
Upvotes: 0
Views: 3573
Reputation: 18109
I think this question is about the difference between executing a script and sourcing a script.
If you execute a script by setting the executable permission and then calling it by it's full or relative path, or just by name if it is in your PATH, then a new shell process will be created to interpret the script (the shell type is determined by the obscure #!/bin/xxx at the start of the script).
If you source a script either by using the source keyword or the . syntax, i.e. one of these:
source test.sh
. test.sh
...then the file will be read and executed in the current shell.
Here are some implications of using source over executing a script that i can think of:
It looks like you want to source your script rather than executing it.
Upvotes: 1
Reputation: 7623
Your script is working just fine. It changes the directory but you can't visibly see that when executing the script. After your script has been executed the old working directory will be in effect again.
If you want to make sure that this is indeed the case then you could try the following:
#!/bin/tcsh
alias ts 'cd /path/goswami/; echo `pwd`'
ts
It will print /path/goswami
as output.
Update: However, if you want to change the directory "outside" the script then don't use the script at all. Just define your alias and use that instead of invoking your script.
Upvotes: 3