Linux的脚本:传递参数 [英] Linux scripting: Passing parameters

查看:92
本文介绍了Linux的脚本:传递参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是新来的脚本,需要很多帮助了解如何在将一个参数传递在文本文件中加载。恐怕你得非常愚蠢的你的答案。请解释一下像我是一个10岁的!

I'm new to scripting and need a lot of help understanding how to load in a text file that will be passed in by a parameter. I'm afraid that you'll have to really dumb down your answers. Please explain like I am a 10 year old!

例如,一个人如何编写一个脚本,接受两个参数,一个是文件路径和一个整数。

For example, how does one write a script that accepts two parameters, a file path and an integer.

另外,你如何运行脚本?将你只需要调用 script.sh -f的data.txt

Also how do you run the script? would you just call script.sh -f data.txt

推荐答案

您能解释一下您的要求详细一点吗?

Could you explain your requirement a bit in detail?

我假定你正在寻找从给定文件中提取第N列。你并不需要解析内AWK命令行参数,而不是仅仅从它们传递上海(1)本身。

I assume you are looking to extract the Nth column from a given file. You don't need to parse command-line parameters within AWK, instead just pass them from sh(1) itself.

# foo.sh
awk "{ print $"$1" }" $2

在这里,我逸出AWK来获取这是位置号码的第一个参数。
如果你觉得太混乱,你可以操纵 ARGC ARGV 。阅读 AWK(1)

希望有所帮助。

这篇关于Linux的脚本:传递参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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