Вопрос

I followed the arch wiki article to create a shell script file with the following functions:

#!/bin/bash
function proxy(){
     echo -n "username:"
     read -e username
     echo -n "password:"
     read -es password
     export http_proxy="http://$username:$password@proxyserver:8080/"
     export https_proxy=$http_proxy
     export ftp_proxy=$http_proxy
     export rsync_proxy=$http_proxy
     export no_proxy="localhost,127.0.0.1,localaddress,.localdomain.com"
     echo -e "\nProxy environment variable set."
 }
 function proxyoff(){
     unset HTTP_PROXY
     unset http_proxy
     unset HTTPS_PROXY
     unset https_proxy
     unset FTP_PROXY
     unset ftp_proxy
     unset RSYNC_PROXY
     unset rsync_proxy
     echo -e "\nProxy environment variable removed."
 } 
case "$1" in
     'proxyon')
              proxyon
              ;;
     'proxyoff')
              proxyoff
              ;;
     *)# default execute
              proxyon
esac

Upon execution (as root and as well as an user) I entered the username password as requested by the script above but I wasn't able to see the aliases as being set!! I printed the 'printenv' to see the environmental variables. Can anyone point out my folly.

Это было полезно?

Решение

Don't execute the script, source it instead. The execution would happen in a subshell and that is what prevents you to see the side-effects that should be caused by the script.

Invoke the script by saying:

source /path/to/script

or

. /path/to/script

(note the space between . and path in the above line)

Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top