Mkdir dynamic variable Help

Matthew Ennis

New Member
Hey,

I'm very new to using CLI and bash scripts (and programming in general) so excuse me if this is bare bones.

Basically the problem I'm having is I have a bash script which needs to make a new directory named as a concatenation of the names of two files that have been passed to the script. I need this to be done using dynamic variables, '$1' and '$2' etc etc..

Something like this:

COMMAND:

bash script.sh one.txt two.txt

CONTENTS OF SCRIPT.SH:

mkdir 'concat_<I don't know what to put it in here to get one.txt and two.txt>'


So the desired directory name is concat_one.txt_two.txt



This is going to be done many times as I'm using this script with a DSL called Nextflow which will read in more files in parallel (three.txt, four.txt etc etc etc..)


Any help and guidance would be much appreciated!
 


kenJackson

Member
Try
Code:
mkdir "$1$2"
or
Code:
mkdir "${1}_$2"
You can always use curly braces, but you only really need them to avoid confusing the command parser. You don't even need them here because $1_ would be an invalid variable.
 

Matthew Ennis

New Member
Try
Code:
mkdir "$1$2"
or
Code:
mkdir "${1}_$2"
You can always use curly braces, but you only really need them to avoid confusing the command parser. You don't even need them here because $1_ would be an invalid variable.

Ah, curly braces. I think that's it. Knew it was something simple.

Thanks a bunch!
 

Members online


Top