我如何创建一个在同一行作为脚本的执行接受用户输入一个bash脚本? [英] How do I create a bash script that accept user input on the same line as the execution of the script?

查看:250
本文介绍了我如何创建一个在同一行作为脚本的执行接受用户输入一个bash脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想我更多的是福利局的比我想象的? :)

I guess I'm more of a newb than I thought? :)

奇怪的是,我知道这是一个简单的答案。我知道我会如何简单,这是尴尬。但是你可以从我想不通怎么连问的问题得当,这可能是为什么我不能google一下问题的标题看到的......我知道这么多的脚本,做到这一点,但我似乎无法找到一个在那一刻,我可以查看弄明白源。

The weird thing is, I know this is an easy answer. I know I will be embarrassed at how simple this is. But you can see from the title of the question that I have can't figure out how to even ask the question properly, which is probably why I can't google it... And I know of so many scripts that do this, but I can't seem to find one at the moment that I can view the source of to figure it out.

编辑:bash脚本

因此​​,这里是我想要完成的任务:

So here's what I want to accomplish:

user@some-machine:~$ myscript variable

在哪里变量的东西,对用户的标签将成为脚本中的变量。我知道如何抓住用户的输入与读命令,但我想通过键入脚本后面是变量的名称,在一行执行的脚本。

Where "variable" is something that the user tags on that will become a variable inside the script. I know how to grab user input with the read command, but I want the script to be executed by typing the name of the script followed by the variable, in one line.

我这个是因为冗长我希望别人会觉得这后来通过谷歌搜索,并得到他们的答复。

I'm being verbose about this because I'm hoping someone else will find this later through a google search and get their answer.

在此先感谢!

凯文

推荐答案

在bash脚本的第一个参数是$ 1,第二个是港币$ 16等...

the first argument in a bash script is $1, second is $2 etc...

这篇关于我如何创建一个在同一行作为脚本的执行接受用户输入一个bash脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆