0

At the bottom of my bash script, after all of my needed bash aliases and functions have been defined, I've got just a single line to be executed when the script is run:

echo "$# args: $@ passed to bash script"

I then define an alias in my ~/.tcshrc to call this script:

alias savall2all 'bash $BACKUP/savall2all.bash \!*'

In the tcsh calling script, the !* is supposed to pass in all of the command line arguments. I then use this alias on the tcsh command line after checking my parameters:

echo $RST
> /Users/My/Documents/DESK/DESK_N2R/RST
echo $HST
> /Users/My/Documents/DESK/DESK_E2M/HST
savall2all $RST $HST
> 1 args: SD02FL=/Volumes/SuperDuper-02-Files passed to bash script

Note first that I pass 2 args to savall2all but it gets only one. Inexplicably, moreover, the parameter the bash script actually gets is something out of the blue. It has nothing to do with the bash script or what I'm passing to it. There is such an environment variable set elsewhere in the ~/.tcshrc calling script but I cannot explain how it's getting pulled into my use of this alias.

I've researched and tried a wide range of variations on both tcsh and bash structure and syntax but get the same result every time.

15
  • 1
    From what you describe here, it should work, so the problem must be coming from something you don't realize is relevant (and hence have left out of your description). That's why we always recommend creating a Minimal, Complete, and Verifiable example of the problem, since it both gives you a way to discover what relevant thing(s) you're not aware of, and gives us the info we need to identify the problem. Commented Apr 27 at 3:49
  • 1
    But in this case, I'd try two basic simplifications first: 1) put that echo command at the beginning, rather than end, of the bash script; 2) pass those arguments to the alias literally rather than via variables. Also, what is that other variable you mentioned, and how is it used (/does it occur at all in the bash script), and does the bash script use the set command at any point? Commented Apr 27 at 3:50
  • 1
    Finally, run your bash script through shellcheck.net and fix what it points out. It may not spot the cause of this specific problem, but it'll help you avoid a bunch of other potential problems. Commented Apr 27 at 3:53
  • 2
    \!* is not necessary. Commented Apr 27 at 8:37
  • 1
    set is not used in bash to define shell variables, but to define shell options and positional parameters. SD01='...', etc, is all you need to define a shell variable. set a=1 actually sets the first positional parameter to the literal string a=1: set a=1; echo "$1" will output a=1, not perform an assignment to a. Commented Apr 30 at 16:24

0

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.