shell脚本 将用户输入的参数设置为当前脚本的参数
时间: 2023-07-08 15:34:20 浏览: 161
您好,可以使用 `set` 命令将用户输入的参数设置为当前脚本的参数。例如,以下是一个示例的 shell 脚本,它会提示用户输入参数,然后将用户输入的参数设置为当前脚本的参数:
```bash
#!/bin/bash
echo "请输入参数:"
read -r arg
set -- "$arg" # 将用户输入的参数设置为当前脚本的参数
echo "当前脚本的参数为:$1"
```
在上面的脚本中,`set -- "$arg"` 命令将用户输入的参数 `$arg` 设置为当前脚本的参数,这样在后续的脚本中就可以通过 `$1` 来引用该参数。
阅读全文
相关推荐
![sh](https://img-home.csdnimg.cn/images/20250102104920.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![zip](https://img-home.csdnimg.cn/images/20241231045053.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![pdf](https://img-home.csdnimg.cn/images/20241231044930.png)
![txt](https://img-home.csdnimg.cn/images/20241231045021.png)
![rar](https://img-home.csdnimg.cn/images/20241231044955.png)
![pptx](https://img-home.csdnimg.cn/images/20241231044947.png)