0

I have a bash script which works like this;

.
├── script.sh
├── configs
|   ├── conf1.conf
|   └── conf2.conf

script.sh;

#!/bin/bash

function test {
  echo $var1
}

case $1 in
  $1) cfg=$1 ;;
esac

cfg_file=~/config/"$cfg.conf" 

if [ -f "$cfg_file" ]; then
  . "$cfg_file"
  test $1
else
  echo "$1.conf doesn't exist"
  exit 1
fi

conf1.conf;

var1=test1

conf2.conf;

var1=test2

So in this script, if you run ./script.sh conf1 then it will use the conf1.conf file and will print test1 from var1 to shell. Same apply for conf2 and so on.

I'm trying to change the source of the config files to a remote source like this;

cfg_file='http://example.com/configs/"$cfg.conf"'

I've tried this very code above but it couldn't locate the config file.

How can I do this in bash, if possible?

Marry Jane
  • 305
  • 2
  • 15
  • Don't call your own function `test`, it clashes with the built-in. – tripleee Jan 11 '19 at 13:05
  • Thank for the heads up – Marry Jane Jan 11 '19 at 13:07
  • The duplicate is not 100% but you should easily be able to adapt it. Also tangentially, fix your quoting: https://stackoverflow.com/questions/10067266/when-to-wrap-quotes-around-a-shell-variable – tripleee Jan 11 '19 at 13:11
  • I've checked that question but it's asking to run a bash script itself from a url. My bash script is running locally and I'm only trying to fetch config files remotely, not the script itself. – Marry Jane Jan 11 '19 at 13:12
  • 1
    The answer is still that Bash has no built-in HTTP client; use `curl` or `wget` – tripleee Jan 11 '19 at 13:13

0 Answers0