[問題] 如何把current directory存進變數

看板Linux作者 (Jeanias)時間14年前 (2012/01/24 08:39), 編輯推噓1(104)
留言5則, 4人參與, 最新討論串1/1
希望能夠用簡單的方法 把current folder name以string的型式存進變數中 eg. current folder: /home/Documents x=......<-- store 'Documents' into x as string echo x 印出 Documents 不知道可以如何操作呢 可不可能一個command 可以完成~ 我還不會寫 perl 等高階的shell script 謝謝! -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 77.176.65.108 ※ 編輯: irjeanias 來自: 77.176.65.108 (01/24 08:57)

01/24 09:50, , 1F
x=`pwd | sed 's/.*\///g'`
01/24 09:50, 1F

01/24 09:53, , 2F
echo $x
01/24 09:53, 2F

01/24 15:20, , 3F
FOLDER_NAME=$(basename `pwd`)
01/24 15:20, 3F

01/25 02:31, , 4F
謝謝!!!
01/25 02:31, 4F

01/25 12:58, , 5F
咦?好像有個 $PWD 環境變數耶?
01/25 12:58, 5F
文章代碼(AID): #1F7Vsj3P (Linux)