OpenVPN Source vars not working on debian

I need to create a script to automatically install the OpenVPN server. In this script, I need to specify the vars file in the file / etc / openvpn / easy -rsa /

But when I execute the following script in the directory / etc / openvpn / easy-rsa / (with chmod 775 in the script and vars file), it says "xxxx.sh: 3: xxxx. Sh: source: not found:"

#!/bin/bash source ./vars 

When I write .. / vars, it works, but if I want to do it. / clean -all, it says:

Please enter a vars script first (ie. "Source. / Vars") Make sure you edit it to reflect your configuration.

When i do. / clean -all in the same script as .. / vars, it works.

Thanks for your help (and sorry for my bad english: /)

+4
source share
1 answer

When you source (or . ) A file, all commands inside it are read and executed - this includes variable assignments. However, when a variable is assigned, it takes place only for the current shell. When you run the script, a subshell is created - therefore, any variables inside the script are visible only in the subshell, and not in the parent (calling) shell. That's why it works when you run source and clean-all inside the same script, it should also work if you execute both from the command line, i.e.:

 $ . /etc/openvpn/easy-rsa/vars $ /etc/openvpn/easy-rsa/clean-all 
+2
source

Source: https://habr.com/ru/post/1208011/


All Articles