通过bash,输入含有()左右括号的字符串

#include<stdio.h>
#include<string.h>

int main( int argc, char* argv[] )
{
    puts( argv[1] );
    return 0;
}

输入样例:()www
bash: 未预期的符号 `www' 附近有语法错误

阅读 3.4k
1 个回答

可以将包含特殊字符的参数用单引号引起来,或者通过反斜杠转意:

[root@web ~]# ls ()
-bash: syntax error near unexpected token `('
[root@web ~]# ls '()'
ls: cannot access (): No such file or directory
[root@web ~]# ls \(\)
ls: cannot access (): No such file or directory
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进