首页 > 解决方案 > Command line commands in a shell script

问题描述

I have a command that I use in the command line to replace certain lower case characters with upper case, which works fine:

cat file | sed -e 's/^ g/G /;s/^ h/H /;s/^ n/N /;s/^ b/B /' > newfile

Is there a way I can write this into a shell script and call

bash uppercase.sh file

instead of copy and pasting into the command line every time?

Currently when I copy and paste the command into a shell script like:

#!/bin/bash
sed -e 's/^ g/G /;s/^ h/H /;s/^ n/N /;s/^ b/B /'

The terminal becomes unresponsive

标签: bashshell

解决方案


尝试将 '$1' 附加到脚本中的 sed 命令,如下所示:

#!/bin/bash
sed -e 's/^ g/G /;s/^ h/H /;s/^ n/N /;s/^ b/B /' $1

然后,像这样运行它:

bash uppercase.sh file

推荐阅读