在bash中,我们可以将两个shell命令cd
和ls
这样的:组合两个shell命令为一个命令
function cd {
builtin cd "[email protected]" && ls
}
#this will get a list of file after changing into a directory
而且这个
mkcd() { mkdir -p "[email protected]" && cd "[email protected]"; }
#this will create and directory and change into it at once
我们可以做类似的PowerShell的东西吗?如果是这样,我想作出类似的功能,并把它放在我的$ profile
感谢您的任何帮助。
Steeluser
编辑:
我意识到这可能从外壳就像这样:
$> 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函数。
感谢扎克,这个工作! – Animesh 2011-05-08 00:01:49
这很好,但不管理现有目录,并返回'$ null'。看到我的答案。 – 2011-05-08 06:33:06