linux中如何用shell命令分割传递的参数(比如文件名)

参考:https://www.cnblogs.com/silentdoer/p/8798010.html

https://blog.csdn.net/zhanglh046/article/details/52717450

如何用shell命令分割传递的参数(比如文件名)

比如分割netperf-2.7.0.tar.gz

vi test.sh


#!/bin/sh
netperfpath=$1
array=(${netperfpath//./ })
echo array[0]

运行: 

chmod +x test.sh
./test.sh netperf-2.7.0.tar.gz

可以这么理解,//,/ 就是将,替换成空格(还可以如//t/b将t转换为b);如果string="aa bb ccc"那么其实可以直接array=($string)就能将字符串转换为数组;

猜你喜欢

转载自blog.csdn.net/rong11417/article/details/88238780