在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