首页 > 解决方案 > 具有多个输入和 sed 的 Bash 脚本不起作用

问题描述

我有一个包含元素 a、b、c 的文件,我想用我在终端中输入的正确值替换它。我正在使用一个名为 hi.sh 的 .bashrc 脚本。

我将包含元素 a、b、c 的文件名输入为 ifile,并希望将其写入我定义为 offile 的新文件中。

我准备的脚本是:

#!/bin/bash

read date tm MJD ifile ofile
echo Enter date (DD/MM/YYYY) : $date
echo Enter IST - 5:30 HRS time: $tm
echo Enter MJD : $MJD
echo Enter input file with abc var(~/) : $ifile
echo Enter input output file : $ofile

do
sed -e 's/a/$date/g' -e 's/b/$tm/g' -e 's/c/$MJD/g' $ifile > $ofile
done

但是,在终端中运行 bash hi.sh 时,脚本不起作用。

这有什么问题和解决方案?我是使用 bashrc 编写脚本的新手

标签: bashshellsedscripting

解决方案


推荐阅读