1. 程式人生 > >shell 問題備忘

shell 問題備忘

一 ls結果賦給變數

  dirSrc=$(ls test/ -l | awk '/^d/{print $NF}')
  echo "dirSrc is $dirSrc"

二 使用cut查詢最後一個欄位

  echo 'maps.google.com' | rev | cut -d'.' -f 1 | rev

三 shell 獲取結果中的第n列,第n行

  ls -l | awk '{print $5}' | sed -n '2p' (print 到後帶的是你要獲取第幾列,sed -n 是指定第幾行)