Sign up ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It's 100% free, no registration required.

I know little about shell script but I want to try to implement some complicated scripts.

Say I have a doitall.sh with the content like:

zip -j version_a_en.zip en_filea1.txt en_fileb2.json

And a doitall2.sh with the content like:

zip -j version_b_en.zip en_fileb1.txt en_fileb2.json

How can I use "a" and "en" as parameters so that I can use only one script to handle all the similar requirements. Like

./doitall.sh a en

or

./doitall.sh b fr
share|improve this question

1 Answer 1

up vote 2 down vote accepted

The commandline parameters a and en can be accessed in shell scripts using $1 and $2:

#! /bin/bash
zip -j version_"$1"_"$2".zip "$2"_filea1.txt "$2"_fileb2.json

care has to be taken when you have numbers following them in the text, that is why I always tend to put them in double quotes, but in this case you could leave them out.

share|improve this answer
    
The standard way to delimit the variable name is with braces, as in "version_${1}_${2}.zip", with the double quotes around the whole being necessary in case the arguments themselves contain spaces. –  Jonathan Leffler Jan 4 at 15:47

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.