How to pass arguments to 'source' command?
RESOLVED : Thanks to this answer. I was able to pipe in my input to the source command thereby removing my intervention. I created a script to do some of the other things I wanted to do, and added it to the alias, and is working fine.
The command which worked was:
echo $arg1 | source /directory/of/script/script.csh | tee /log-file/destination/filename.dat
the tee
command allowed me to capture the output of the source command into a .dat
file. And for the benefit of others looking for a similar solution, another quick idea : one can pipe in any number of arguments to the command, but take care to pass it in the order in which it will be invoked / asked.
Also, I agree to what others pointed out already, it would not be a good idea to pipe in your credentials like this and script to avoid re-typing every time.
Related videos on Youtube
newbie
Updated on September 18, 2022Comments
-
newbie over 1 year
My
source
command in the CShell goes like this :source /directory/of/script/script.csh
The
script.csh
executes and in between, waits for my password to confirm the identity.I am tired of typing the password everytime I have to
source
. So, since my password is constant, I was thinking of creating an alias which goes like this :alias <alias name> 'source /directory/of/script/script.csh; <my password>'
The only catch is that, it is not taking in my password because, technically,
my password
is executed after the complete execution of thesource
.How do I go about it?
If anyone needs any further info, I am happy to provide.
EDIT: The original
script.csh
CAN NOT be modified to exclude the password because, I am not authorised to make such changes.
EDIT (2) : The actual need is to pass on a value (a particular number, depending on what I am about to do after this) to the shell script
script.csh
while it is being executed, without user intervention.I used the word 'password' because, it was easier to explain using that example as authentication is some thing that is usually asked repeatedly in between a process, every time one tries something, and the execution does not proceed without it, or stops if a wrong input is given.. And, my case is synonymous : I have to give an input for the script to proceed, and it halts if a wrong input is given.
-
slm about 10 yearsWhoa! One that isn't going to work, and 2 don't do that. What's in the
script.csh
that needs your password each time? -
newbie about 10 years
script.csh
is created by my IT admin, and has a lot of other functions. What I want to avoid is, typing my password everytime it pauses.. So, why is it not going to work? Why doessource
command take any arguments? -
slm about 10 yearsWhat are you needing to resource out of this script.csh file everytime? Can you not create another file with just the setting you're changing, and resource that instead?
-
newbie about 10 yearsthe
source
command actually pulls out the list of all the versions of one software installed in our server. I am to chose from that list and use another command to open that version of the software. And, since I need to work with different versions at different times, I have to source it more than once every day.. So, the script is designed to ask for a passkey before I chose the version I want. -
Michael Mrozek about 10 yearsYou probably need to use something like expect, but putting your password in plaintext in a login script is really not a good idea
-
slm about 10 yearsI hope you understand our line of questioning and apprehension, since most of us are admins of one sort or another and what you're asking us is "how do I go around X". I know I'd be mad if some other admin told my users how to circumvent something like this. Have you tried to discuss it w/ your admins to understand why this is in place to begin with? Seems like they should be trying to help you be efficient too.
-
slm about 10 yearsAlso if you're running multiple shells on your system, you could keep one per version setup, and just run the specific tool version from shellX and another from shellY without having to re-source it. The shells are sep. processes and so their setups are isolated from one another.
-
newbie about 10 yearsI am a software tester, and I need to work with different versions of the dev. build each day. So, keeping a terminal open for each version I run (even though feasible) will clutter the already cluttered workspaces.. :D P.S. : Please see edit (2)
-