1

I am not expert of bash scripting, but I really don't understand what is appening here. My script is this:

#!/usr/bin/env bash

echo "calling asetup"
export ATLAS_LOCAL_ROOT_BASE=/cvmfs/atlas.cern.ch/repo/ATLASLocalRootBase
source ${ATLAS_LOCAL_ROOT_BASE}/user/atlasLocalSetup.sh
asetup 17.6.0,slc5

echo "Now running..."
echo "argument $@"

I call it with as ./myscript -v, the output is:

calling asetup
atlasLocalSetup.sh: invalid option -- 'v'
'atlasLocalSetup.sh --help' for more information
./prova.sh: line 12: asetup: command not found
Now running...
argument -v

on the second line, what is atlasLocalSetup.sh: invalid option -- 'v'?? Why isatlasLocalSetup.sh called with the -v option?

2 Answers 2

3

The sourced script is run in the current environment without changing the value of positional parameters. The value of "$@" is the same for the called script as for the calling script.

You can use

set --

to clear the positional parameters. If you need to save them, use

pos_par=("$@")
set --
source script.sh
set -- "${pos_par[@]}"
Sign up to request clarification or add additional context in comments.

Comments

0

It seems like you are calling your script file with a -v option. Note that source does not change the values of the commandline parameters ($1) unless positional parameters are provided to the source command.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.