在 Bash 中,我们可以像这样组合两个 shell 命令 cd
和 ls
:
function cd {
builtin cd "$@" && ls
}
#this will get a list of file after changing into a directory
还有这个
mkcd () { mkdir -p "$@" && cd "$@"; }
#this will create and directory and change into it at once
我们可以在 Powershell 中做类似的事情吗?如果是这样,我想制作类似的功能并将其放入我的 $profile
感谢您的帮助。
钢铁用户
编辑:
我意识到这可以像这样从 shell 中完成:
$> pwd|ls
Directory: D:\ps
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 5/7/2011 9:40 PM config
d---- 5/7/2011 9:40 PM output
d---- 5/8/2011 3:37 AM static
-a--- 5/8/2011 3:36 AM 485 create-static-files.ps1
这可以放在这样的配置文件中:
function pl
{
pwd|ls
}
并且可以从shell中调用
ps$ pl
Directory: D:\ps
Mode LastWriteTime Length Name
---- ------------- ------ ----
d---- 5/7/2011 9:40 PM config
d---- 5/7/2011 9:40 PM output
d---- 5/8/2011 3:37 AM static
-a--- 5/8/2011 3:36 AM 485 create-static-files.ps1
但我不知道如何执行 mkcd 功能。
最佳答案
这样的事情应该可行。
Function mkcd {
mkdir $args[0]
cd $args[0]
}
这只是powershell中的一个普通函数。参见 http://technet.microsoft.com/en-us/library/dd347712.aspx了解更多。
关于bash - 将两个 shell 命令组合成一个命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5924646/