Bash字符串串联
时间:2020-01-09 10:37:20 来源:igfitidea点击:
如何在BASH下连接两个字符串?
我有两个存储在两个不同变量(_p =/delta和_u = aqua)中的字符串,如何将其连接并分配给bash中的另一个变量?
您可以如下使用参数替换:
_p="/delta"
_u="aqua"
### join two $vars ###
out="${_p}${_u}"
echo "${_p}${_u}"
echo "${_p} and ${_u}"
echo "${_p}/${_u}"
echo "Output: $out"
另一个例子:
#!/bin/bash
_domain="${1:-example.com}"
_root="/chroot"
_path="${_root}/${_domain}"
echo "Host: ${HOSTNAME}@$(date) by $USER"
echo
echo "Setting Apache for ${_domain} @ ${_path}...."
# setupJail "${_domain}" "${_path}"
输出示例:
./setup.httpd theitroad.com Host: www34.theitroad.com@Fri Nov 19 01:44:03 IST 2010 by root Setting Apache for theitroad.com @ /chroot/theitroad.com...

