• Want to receive the latest contracting news and advice straight to your inbox? Sign up to the ContractorUK newsletter here. Every sign up will also be entered into a draw to WIN £100 Amazon vouchers!

Shell Script Help

SimonMac

TykeLike
Thanks received
1,850
If this was windows I could knock this out in seconds, but it's linux and I haven't much experience, or more to the point examples that I reverse engineer and rip off

I have two variables say "name" and "location"

What I want to be able to to is create a script that will allow me to pick one from each pre-determined list and then use them in a series of file paths to then move them to a single place

Code:
Source\%name%\%1%\filename1
Source\%name%\%2%\filename2
Source\%name%\%3%\filename3

Source\%location%\%a%\filename2
Source\%location%\%b%\filename2
Source\%location%\%c%\filename2

cp source\%var1%\filename1 destination\filename1
cp source\%var2%\filename2 destination\filename2

./destination/run.sh

Firstly does the ask make sense?
 
If this was windows I could knock this out in seconds, but it's linux and I haven't much experience, or more to the point examples that I reverse engineer and rip off

I have two variables say "name" and "location"

What I want to be able to to is create a script that will allow me to pick one from each pre-determined list and then use them in a series of file paths to then move them to a single place

Code:
Source\%name%\%1%\filename1
Source\%name%\%2%\filename2
Source\%name%\%3%\filename3

Source\%location%\%a%\filename2
Source\%location%\%b%\filename2
Source\%location%\%c%\filename2

cp source\%var1%\filename1 destination\filename1
cp source\%var2%\filename2 destination\filename2

./destination/run.sh

Firstly does the ask make sense?

Still need a hand with this? If so PM me.
 
No idea if this is the most elegant way but it seems to work so far

Code:
#!/bin/bash
# Bash Menu Script Example

folder=/home/simonmac

auths=(name1 name2 name3 name4 name5 name6)
select auth in "${auths[@]}"; do
   cp $folder/auth/$auth/auth.json $folder/AppName/configs/auth.json
   break
done

configs=(config1 config2 config3)
select config in "${configs[@]}"; do
    cp $folder/configs/$config/config.json $folder/AppName/configs/config.json
    break
done

./AppName/run.sh
 

Advertisers

Back
Top