在shell脚本中,$1变量表示第一个命令行参数。它应该在脚本中以"$1"的格式书写,即加上双引号,以避免出现空格等特殊字符导致的错误。例如:

#!/bin/bash

echo "The first command line argument is: $1"

在执行脚本时,可以传入参数,并且在脚本中使用$1变量来引用这个参数:

$ ./test.sh "hello world"
The first command line argument is: hello world

原文地址: http://www.cveoy.top/t/topic/hkOh 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录