1. 程式人生 > >Linux shell程式設計常用語法

Linux shell程式設計常用語法

1 常用語法 1.1 shell程式設計空格注意事項 shell 程式設計空格注意事項https://blog.csdn.net/codeheng/article/details/51177344?from=timeline&isappinstalled=0 1.2 shell陣列 Shell 陣列https://www.cnblogs.com/cisum/p/8010677.html?from=timeline&isappinstalled=0 1.3 字串分割為陣列 # IFS:Internal Field Seprator,Linux shell內部域分隔符,為系統變數,預設為空格 # 例子1 pid_line=`ps -A | grep zygote64` OLD_IFS="$IFS"  IFS=" "  arr=($pid_line) IFS="$OLD_IFS"  pid=${arr[0]} # 例子2 has_prio=0 prio="5" old_ionice=`ionice -p 1` OLD_IFS="$IFS"  IFS=" " arr=($old_ionice) IFS="$OLD_IFS"  class=${arr[0]} if [ $class =~ "best-effort" ] || [ $class =~ "real-time" ]; then     if [ ${#arr[@]} -gt 2 ]; then         has_prio=1         prio=${arr[2]}     fi fi