Linux bash--字符串拼接



#!/usr/bin/env bash concat_strings() { local separator=$1 # 分隔符 shift # 移动参数位置 local result="" # 结果字符串初始化为空 # 循环遍历剩余的参数,拼接字符串 for string in "$@"; do result="${result}${separator}${string}" separator=$1 # 更新分隔符 done # 移除字符串首部的分隔符 result="${result#$separator}" echo "$result" # 输出拼接后的字符串 } result="" for device in $(ls '/mnt' | awk '{print $1}'); do echo "this is third $device" #result="$result $(concat_strings " -d,r " /mnt/$device)" result="$result -d,r /mnt/$device" done echo "$result"

 

posted @ 2024-03-08 16:34  zhihua  阅读(216)  评论(0编辑  收藏  举报