How pass the input parameter to a file in the script ?
OS version: RHEL 6.7
myTextFile.txt file is referred within Script1.sh script,
I only execute Script1.sh and I want the input variable to be passed inside myTextFile.txt . Any idea how I can do this ?
Requirement1.
When I execute script1 like below, the input parameter should be passed inside myTextFile.txt
But, it only prints the following with my current script
Requiremen2:
I want the value that is passed as the parameter to be enclosed in single quotes in the output. In the above example , the string hello is passed as the parameter and I want the output to be 'hello'
As things currently stand, your script is in fact doing precisely what it should. To recap, at the moment your script contains one line of code, namely:
cat myTextFile.txt
So all this script will ever do is display the contents of a file in the current directroy called myTextFile.txt. It does not take any input, accept any parameters, or do anything else. In short, running this script is 100% equivalent to just directly typing cat myTextFile.txt at the shell prompt yourself.
If instead you want a script to return as output whatever single input parameter is passed to it, then you don't need to use a file for this. To get both the requirements you list, something like this would suffice:
In my real life scenario, I have program being called inside script1.sh . This program doesn't take any input parameters.
Instead, it reads a config file (config.txt) and executes based on the input parameter. This is why I need to pass the input parameter to config.txt
Ah, OK - I think I understand. Something like this then, maybe ?
There are various ways of doing this kind of thing, but if you always know the file will contain only one single string, and you want to stick to as close to your original script as you can, then this should be sufficient.
Hi,
I have an XML file like the following...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ONDEMAND_JOB VERSION="5.1" LOCALE="en_US">
<IMPORT_JOBSET TC_CONNECTION_NAME="default" ENVIRONMENT="PRD" USERNAME="Administrator" PASSWORD="AdminPassword" CALENDAR="Main Monthly Calendar"... (3 Replies)
Hi,
I have an XML file like the following...
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ONDEMAND_JOB VERSION="5.1" LOCALE="en_US">
<IMPORT_JOBSET TC_CONNECTION_NAME="default" ENVIRONMENT="PRD" USERNAME="Administrator" PASSWORD="AdminPassword" CALENDAR="Main Monthly Calendar"... (2 Replies)
Dear all
Does anybody know how to pass the password as input parameter to scp or rsync in unix scripts?
I have tried echo <password> | scp filename username@<ip address>:/filepath/ .
But it does not work.
BTW, I dont want to setup ssh trust between servers in this adhoc task.
Regards,... (2 Replies)
Hi Guys,
I have a file in the format Parmater=value. I want to read the value and pass it to corresponding Variable.
The Parameter file is as follows
Number=23
Text1=mango
Text2=yup
'Number' value needs to be read and passed to ID variable. Also, 'Text1' value needs to be passed to... (9 Replies)
Hi friends.
i am newbie to shell scripting. I need to create a script where i will be passing 2 parameters to the script and based on that it should work.
For ex: start_proc a 2 or start_proc b 2
start_proc a 2 --- this should bring up 2 processes as i define inside the script.
start_proc... (2 Replies)
Hi,
i am new to awk. I am using csv2pipe script(shown below)
BEGIN { FS=SUBSEP; OFS="|" }
{
result = setcsv($0, ",")
print
}
# setcsv(str, sep) - parse CSV (MS specification) input
# str, the string to be parsed. (Most likely $0.)
# sep, the separator between the values.
#
#... (6 Replies)
I would like to write a scirpt a.sh that it first checks the first parameter of the input. If it fulfill some condition ,then run an executable program b by using all the parameter.
ie.
> ./a.sh 10 20 30 40 50
Then a.sh first checks the first parameter, 10, if it mathes the requirement, then... (2 Replies)
Hi, I am trying to write a ftp script which will read a file for filenames and ftp those files to another server. Here's my ftp script, but it's scanning the current directory for file names.
My question is how can I pass multiple files (these files will have the name of data files that need to... (0 Replies)
I have a piece of code that I do not want to continuously repeat. I want to call script2 from script1 and pass a parameter. Here is an example:
Script1:
.......
nohup ./Script2 PARAMETER
.......
Script2:
if
# Checks if any params.
then
echo "No parameters passed to function."
... (4 Replies)