Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我试图将 whoami 的输出更改为大写后将其保存到不同的变量。请帮我。我是 shell 脚本的新手。
提前致谢。
使用纯bash
bash
x=$(whoami) v=${x^^}
使用tr
tr
v=$(whoami | tr 'a-z' 'A-Z')
或者
v=$(whoami | tr [:lower:] [:upper:])
使用awk
awk
v=$(whoami | awk '{print toupper($0)}')
使用perl
perl
v=$(whoami | perl -e 'print uc <>')