如何将参数传递到Linux Bash脚本? [英] How to pass parameters to a Linux Bash script?

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

问题描述

我有一个Linux的bash脚本'myshell。我希望它读两个日期作为参数,例如: myshell日期1日期2 。我是一个Java程序员,但是不知道怎么写来完成这件事的脚本。

脚本的其余部分是这样的:

  sed的S / $日期1 / $日期2 / g的wlacd_stat.xml> tmp.xml
MV tmp.xml wlacd_stat.xml


解决方案

在使用 $ 1 $ 2 您脚本如

  = DATE1$ 1
DATE2 =$ 2
SEDS / $日期1 / $日期2 / g的wlacd_stat.xml> temp.xml; MV temp.xml wlacd_stat.xml #Semicolon也可以替换为新行

I have a Linux bash script 'myshell'. I want it to read two dates as parameters, for example: myshell date1 date2. I am a Java programmer, but don't know how to write a script to get this done.

The rest of the script is like this:

sed "s/$date1/$date2/g" wlacd_stat.xml >tmp.xml
mv tmp.xml wlacd_stat.xml

解决方案

you use $1, $2 in your script eg

date1="$1"
date2="$2"
sed "s/$date1/$date2/g" wlacd_stat.xml >temp.xml ;mv temp.xml wlacd_stat.xml #Semicolon can also replaced with a newline

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

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