Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I pass arguments to bash?

Tags:

bash

macos

So I am writing a bash script which will decrypt a file so I what the syntax of the the command to be decrypt [file.jpg] So far this is my script :

openssl enc -d -aes-256-cbc -in file.jpg > file
 echo "Please make sure you add the correct extension to 
the file."

Spent a lot time trying to achieve my goal but it doest work so I would like some help. Like suppose the file name is movie.mov I should be able to decrypt it using decrypt movie.mov or any other file.

like image 654
nobody user Avatar asked Oct 23 '25 15:10

nobody user


2 Answers

Arguments on bash script are received with $1 for first arg, $2 for second etc...

So your script should looks like

openssl enc -d -aes-256-cbc -in $1 > file

See here

like image 62
jseguillon Avatar answered Oct 26 '25 04:10

jseguillon


You can access parameters inside a bash script using the variables $1, $2, $3. $1 is the first argument, $2 the second ...

If you run

decrypt file.jpg

You can access file.jpg in your bash script with following code:

openssl enc -d -aes-256-cbc -in $1 > file
echo "Please make sure you add the correct extension to the file."
like image 21
Robin Avatar answered Oct 26 '25 05:10

Robin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!