read -p "enter some words :" $PASTE
curl -s "example.com/${PASTE} | code continues
我想要做的是,如果用户输入两个或多个单词,我想用 PASTE
中的 - 替换空格变量。
示例:
PASTE=default application
新粘贴:
PASTE=default-application
我怎样才能做到这一点?
最佳答案
见下文,使用“/”修饰符将“”替换为“-”。注意“读取”命令中的拼写错误修复:
# Notice no '$' for PASTE.
read -p "enter some words :" PASTE
# Replace ALL ' ' with '-'
PASTE=${PASTE// /-}
curl -s "website.com/${PASTE} | code continues
关于linux - 将 shell 变量中的空格替换为 -,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59434460/