How do I cd and then ls in my cshrc











up vote
1
down vote

favorite












I want to be able to cd into a path and have it ls automatically.
I have tried doing a function such as



cs() { cd "@a" ; ls}


but this results in an error saying "badly placed ()" so I do not think I can do functions. I have also tried



alias cs ' cd !:1 ; ls '


I can source my .cshrc with this but when I call it, it doesn't do anything and I am still in the same folder.










share|improve this question









New contributor




Makuza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • See also alias cwdcmd ls (assuming your csh is actually tcsh)
    – Stéphane Chazelas
    2 days ago

















up vote
1
down vote

favorite












I want to be able to cd into a path and have it ls automatically.
I have tried doing a function such as



cs() { cd "@a" ; ls}


but this results in an error saying "badly placed ()" so I do not think I can do functions. I have also tried



alias cs ' cd !:1 ; ls '


I can source my .cshrc with this but when I call it, it doesn't do anything and I am still in the same folder.










share|improve this question









New contributor




Makuza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.




















  • See also alias cwdcmd ls (assuming your csh is actually tcsh)
    – Stéphane Chazelas
    2 days ago















up vote
1
down vote

favorite









up vote
1
down vote

favorite











I want to be able to cd into a path and have it ls automatically.
I have tried doing a function such as



cs() { cd "@a" ; ls}


but this results in an error saying "badly placed ()" so I do not think I can do functions. I have also tried



alias cs ' cd !:1 ; ls '


I can source my .cshrc with this but when I call it, it doesn't do anything and I am still in the same folder.










share|improve this question









New contributor




Makuza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











I want to be able to cd into a path and have it ls automatically.
I have tried doing a function such as



cs() { cd "@a" ; ls}


but this results in an error saying "badly placed ()" so I do not think I can do functions. I have also tried



alias cs ' cd !:1 ; ls '


I can source my .cshrc with this but when I call it, it doesn't do anything and I am still in the same folder.







linux ls cd-command csh






share|improve this question









New contributor




Makuza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Makuza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 2 days ago









Jeff Schaller

37.8k1053122




37.8k1053122






New contributor




Makuza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 2 days ago









Makuza

82




82




New contributor




Makuza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Makuza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Makuza is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












  • See also alias cwdcmd ls (assuming your csh is actually tcsh)
    – Stéphane Chazelas
    2 days ago




















  • See also alias cwdcmd ls (assuming your csh is actually tcsh)
    – Stéphane Chazelas
    2 days ago


















See also alias cwdcmd ls (assuming your csh is actually tcsh)
– Stéphane Chazelas
2 days ago






See also alias cwdcmd ls (assuming your csh is actually tcsh)
– Stéphane Chazelas
2 days ago












1 Answer
1






active

oldest

votes

















up vote
1
down vote



accepted










You were very very close. 
Unix loves backslashes; Unix eats backslashes for breakfast. 
You need



alias cs 'cd !:1; ls'


If you look at the documentation for csh (and its descendants),
you'll see that ! refers to the history mechanism,
which lets you refer to previous command(s). 
The simplest example is !!,
which recalls and repeats the most recent command. 
!:1 means word #1 from the referenced command
(where the command itself is word #0;
so, for example, in grep needle *.txt
!:0 is grep and !:1 is needle).



Bash and other descendants of the Bourne shell have a feature
that is very similar.



C shell aliases are a little weird. 
When you run an alias, the command that you typed
(e.g., cs vacation_photographs) is treated as the "previous command". 
So, when the alias runs, !:1 is replaced with vacation_photographs.



The catch is that this happens when the alias runs. 
But history expansion happens when the alias is defined, too.
So, for example, if your .cshrc says



set prompt = '% '
alias cs 'cd !:1; ls'


then !:1 is evaluated as prompt,
and the alias is defined as cd prompt; ls
To be able to refer to the command that you typed
(vacation_photographs),
you need to define the alias to be cd !:1; ls,
and so you need to use the backslash
to defer the interpretation of the !:1,
so it will be evaluated when the alias is run
instead of when it is defined.



If you've been doing



alias cs 'cd !:1; ls'


and it doesn't do anything (not even give you an error message),
I cannot explain that.






share|improve this answer























  • Thank you! This worked. Just wondering, why is it that the was required?
    – Makuza
    2 days ago










  • AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
    – Stéphane Chazelas
    2 days ago











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});






Makuza is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487420%2fhow-do-i-cd-and-then-ls-in-my-cshrc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote



accepted










You were very very close. 
Unix loves backslashes; Unix eats backslashes for breakfast. 
You need



alias cs 'cd !:1; ls'


If you look at the documentation for csh (and its descendants),
you'll see that ! refers to the history mechanism,
which lets you refer to previous command(s). 
The simplest example is !!,
which recalls and repeats the most recent command. 
!:1 means word #1 from the referenced command
(where the command itself is word #0;
so, for example, in grep needle *.txt
!:0 is grep and !:1 is needle).



Bash and other descendants of the Bourne shell have a feature
that is very similar.



C shell aliases are a little weird. 
When you run an alias, the command that you typed
(e.g., cs vacation_photographs) is treated as the "previous command". 
So, when the alias runs, !:1 is replaced with vacation_photographs.



The catch is that this happens when the alias runs. 
But history expansion happens when the alias is defined, too.
So, for example, if your .cshrc says



set prompt = '% '
alias cs 'cd !:1; ls'


then !:1 is evaluated as prompt,
and the alias is defined as cd prompt; ls
To be able to refer to the command that you typed
(vacation_photographs),
you need to define the alias to be cd !:1; ls,
and so you need to use the backslash
to defer the interpretation of the !:1,
so it will be evaluated when the alias is run
instead of when it is defined.



If you've been doing



alias cs 'cd !:1; ls'


and it doesn't do anything (not even give you an error message),
I cannot explain that.






share|improve this answer























  • Thank you! This worked. Just wondering, why is it that the was required?
    – Makuza
    2 days ago










  • AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
    – Stéphane Chazelas
    2 days ago















up vote
1
down vote



accepted










You were very very close. 
Unix loves backslashes; Unix eats backslashes for breakfast. 
You need



alias cs 'cd !:1; ls'


If you look at the documentation for csh (and its descendants),
you'll see that ! refers to the history mechanism,
which lets you refer to previous command(s). 
The simplest example is !!,
which recalls and repeats the most recent command. 
!:1 means word #1 from the referenced command
(where the command itself is word #0;
so, for example, in grep needle *.txt
!:0 is grep and !:1 is needle).



Bash and other descendants of the Bourne shell have a feature
that is very similar.



C shell aliases are a little weird. 
When you run an alias, the command that you typed
(e.g., cs vacation_photographs) is treated as the "previous command". 
So, when the alias runs, !:1 is replaced with vacation_photographs.



The catch is that this happens when the alias runs. 
But history expansion happens when the alias is defined, too.
So, for example, if your .cshrc says



set prompt = '% '
alias cs 'cd !:1; ls'


then !:1 is evaluated as prompt,
and the alias is defined as cd prompt; ls
To be able to refer to the command that you typed
(vacation_photographs),
you need to define the alias to be cd !:1; ls,
and so you need to use the backslash
to defer the interpretation of the !:1,
so it will be evaluated when the alias is run
instead of when it is defined.



If you've been doing



alias cs 'cd !:1; ls'


and it doesn't do anything (not even give you an error message),
I cannot explain that.






share|improve this answer























  • Thank you! This worked. Just wondering, why is it that the was required?
    – Makuza
    2 days ago










  • AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
    – Stéphane Chazelas
    2 days ago













up vote
1
down vote



accepted







up vote
1
down vote



accepted






You were very very close. 
Unix loves backslashes; Unix eats backslashes for breakfast. 
You need



alias cs 'cd !:1; ls'


If you look at the documentation for csh (and its descendants),
you'll see that ! refers to the history mechanism,
which lets you refer to previous command(s). 
The simplest example is !!,
which recalls and repeats the most recent command. 
!:1 means word #1 from the referenced command
(where the command itself is word #0;
so, for example, in grep needle *.txt
!:0 is grep and !:1 is needle).



Bash and other descendants of the Bourne shell have a feature
that is very similar.



C shell aliases are a little weird. 
When you run an alias, the command that you typed
(e.g., cs vacation_photographs) is treated as the "previous command". 
So, when the alias runs, !:1 is replaced with vacation_photographs.



The catch is that this happens when the alias runs. 
But history expansion happens when the alias is defined, too.
So, for example, if your .cshrc says



set prompt = '% '
alias cs 'cd !:1; ls'


then !:1 is evaluated as prompt,
and the alias is defined as cd prompt; ls
To be able to refer to the command that you typed
(vacation_photographs),
you need to define the alias to be cd !:1; ls,
and so you need to use the backslash
to defer the interpretation of the !:1,
so it will be evaluated when the alias is run
instead of when it is defined.



If you've been doing



alias cs 'cd !:1; ls'


and it doesn't do anything (not even give you an error message),
I cannot explain that.






share|improve this answer














You were very very close. 
Unix loves backslashes; Unix eats backslashes for breakfast. 
You need



alias cs 'cd !:1; ls'


If you look at the documentation for csh (and its descendants),
you'll see that ! refers to the history mechanism,
which lets you refer to previous command(s). 
The simplest example is !!,
which recalls and repeats the most recent command. 
!:1 means word #1 from the referenced command
(where the command itself is word #0;
so, for example, in grep needle *.txt
!:0 is grep and !:1 is needle).



Bash and other descendants of the Bourne shell have a feature
that is very similar.



C shell aliases are a little weird. 
When you run an alias, the command that you typed
(e.g., cs vacation_photographs) is treated as the "previous command". 
So, when the alias runs, !:1 is replaced with vacation_photographs.



The catch is that this happens when the alias runs. 
But history expansion happens when the alias is defined, too.
So, for example, if your .cshrc says



set prompt = '% '
alias cs 'cd !:1; ls'


then !:1 is evaluated as prompt,
and the alias is defined as cd prompt; ls
To be able to refer to the command that you typed
(vacation_photographs),
you need to define the alias to be cd !:1; ls,
and so you need to use the backslash
to defer the interpretation of the !:1,
so it will be evaluated when the alias is run
instead of when it is defined.



If you've been doing



alias cs 'cd !:1; ls'


and it doesn't do anything (not even give you an error message),
I cannot explain that.







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









G-Man

12.8k93164




12.8k93164












  • Thank you! This worked. Just wondering, why is it that the was required?
    – Makuza
    2 days ago










  • AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
    – Stéphane Chazelas
    2 days ago


















  • Thank you! This worked. Just wondering, why is it that the was required?
    – Makuza
    2 days ago










  • AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
    – Stéphane Chazelas
    2 days ago
















Thank you! This worked. Just wondering, why is it that the was required?
– Makuza
2 days ago




Thank you! This worked. Just wondering, why is it that the was required?
– Makuza
2 days ago












AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
– Stéphane Chazelas
2 days ago




AFAIK, bash and zsh are the only Bourne-like shells that have implemented csh-like history expansion.
– Stéphane Chazelas
2 days ago










Makuza is a new contributor. Be nice, and check out our Code of Conduct.










draft saved

draft discarded


















Makuza is a new contributor. Be nice, and check out our Code of Conduct.













Makuza is a new contributor. Be nice, and check out our Code of Conduct.












Makuza is a new contributor. Be nice, and check out our Code of Conduct.
















Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.





Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


Please pay close attention to the following guidance:


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f487420%2fhow-do-i-cd-and-then-ls-in-my-cshrc%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Entries order in /etc/network/interfaces

新発田市

Grub takes very long (several minutes) to open Menu (in Multi-Boot-System)