1.提取數字到變量html
temp = `echo "helloworld20181212 | tr -cd "[0-9]""` echo ${temp}
2.釋義tr -cd "[0-9]"python
tr是translate的縮寫,主要用於刪除文件中的控制字符,或者進行字符轉換shell
-d表示刪除,[0-9]表示全部數字,-c表示對條件取反bash
tr -cd "[0-9]" 的即:剔除非數字的字符,即輸出 20181212.net
ps: 標準輸入stdin,標準輸出stdout,標準錯誤stderr 分別對應 0,1,2 code
2>&1是將標準錯誤輸出到標準輸出中htm
&>file 將標準輸出和標準錯誤輸出都重定向到文件file中blog
參考資料:字符串