Simon Scott Simon Scott - 2 months ago 10
Linux Question

Creating a simple bash script that uses cat and has 3 arguments

I have this bash command I am using to cat the output of two java programs that take 1 parameter each into a file:

cat file.ext | java program1 argument1 | java program2 argument2 > argument3

argument3 is a optional and if it is not provided it should just be file.srtd

How can I create a bash script for this?


In bash, the variable $n is the n'th argument.

The variable $# is the number of arguments given by the user.

So you can do somthing like that:


if (( $# < 3 )) ; then

cat file.ext | java program1 $1 | java program2 $2 > $3

You can look here for more examples