I use SCP a lot to transfer log files from servers to a jumpbox where I can analyse and troubleshoot etc. If I have a cluster of servers and I want to create a set of subdirectories I do it like this:
mkdir -p /foo/bar-nnn/{mailserver,dnsserver,minecraftserver,syslogserver}
Lets's say 'bar-nnn' is a reference of sorts; be that a ticket number or incident etc. What I want to be able to do is run a script or a shell command which will prompt me for what 'bar-nnn' should be then go and create all the subfolders required.
I'm pretty sure I'm going to need a for loop but can't quite get my head around it.
${dir}
instead of"$dir"
, or is it the same? – FelixJN Feb 17 '16 at 13:45
– Moif Murphy Feb 17 '16 at 13:45read -p "Folder name: " dir; mkdir -p /foo/${dir}/{mailserver,dnsserver,minecraftserver,syslogserver}
${dir}ectory
vs$directory
is where the distinction really makes a difference. The former being the value of $dir ending with 'ectory', the latter being the value of $directory. – Devon Feb 17 '16 at 15:35