我正在尝试在$()中使用变量,但它不起作用,不知道我做错了什么?
我刚刚开始使用此脚本,请参阅以下内容:
#!/bin/bash
echo "Please enter the username (without domain and in lowercase)"
read $username
echo "$username"
userid="$(id -u $username)"
echo "$userid"
echo $ userid的结果为0?它应该给我用户的用户ID?
答案 0 :(得分:1)
read username
userid="$(id -u "$username")"
echo "$userid"
$
“双引号”每个包含空格/元字符和每个扩展的文字:"$var"
,"$(command "$var")"
,"${array[@]}"
,"a & b"
。使用'single quotes'
代码或文字$'s: 'Costs $5 US'
,ssh host 'echo "$HOSTNAME"'
。见
http://mywiki.wooledge.org/Quotes
http://mywiki.wooledge.org/Arguments
http://wiki.bash-hackers.org/syntax/words