简体   繁体   English

从目录导航回来时 cd && ls bash 函数问题

[英]cd && ls bash function problems when navigating back from directory

I figured out that very often I use both the cd and ls commands one after the other.我发现我经常一个接一个地使用 cd 和 ls 命令。 This is when I decided to create a bash function for it.这是我决定为它创建一个 bash 函数的时候。

The code that I inserted into the bashrc file is this:我插入到 bashrc 文件中的代码是这样的:

function cs () {
  cd "$@" && ls;
}

The problem that I have is that the output of "ls" is good but I do not really navigate to that directory.我遇到的问题是“ls”的输出很好,但我并没有真正导航到该目录。

For example, when I call "cs Downloads/" I get as an output the content of Downloads but I do not navigate inside it.例如,当我调用“cs Downloads/”时,我将下载内容作为输出,但我不会在其中导航。

I am new to the bash and I am sorry if I do any noob mistake.我是 bash 的新手,如果我犯了任何菜鸟错误,我很抱歉。

The function works well for me when dropped into ~/.bashrc and not called with more than one parameter.当放入~/.bashrc并且不使用多个参数调用时,该函数对我来说效果很好。 Here's a cleaned-up version that addresses minor issues:这是一个解决小问题的清理版本:

function cs() {
  cd "$1" && ls
}

If you still have problems with that then please provide more details in your question: How you call it, what's the exact output, and what you expected instead.如果您仍然有问题,那么请在您的问题中提供更多详细信息:您如何称呼它,确切的输出是什么,以及您所期望的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM