Need to pass variable in a command and assign value to a variable
Hello All,
Hope you're doing well !
I am trying below command to be passed in a shell script, header_date_14 is a variable and $1 is the name of a file I intend to pass as a command line argument, however command line argument is not being accepted.
Any pointers will be greatly helpful !
Thank you !
Ekta
Moderator's Comments:
Please use CODE tags as required by forum rules!
Last edited by RudiC; 06-27-2017 at 04:12 AM..
Reason: Added CODE tags.
I am trying below command to be passed in a shell script, header_date_14 is a variable and $1 is the name of a file I intend to pass as a command line argument, however command line argument is not being accepted.
You should never NEVER use constructs like $1 directly in your code. You see, $1, $2, etc. are positional parameters, not variables. $1 isn't the name of a variable just happening to have the name "1", like "$foo", it is the first parameter passed to this specific context - and what "this specific context" means can change (and does so) from context to context.
Therefore instead of doing:
do it like this:
This also gives you the opportunity to give a meaningful name to the variable like "inputfile", instead of "$1", which won't tell you by its name what it is supposed to contain.
Below is the command, which is used for accessing multi files, what I was trying to do is to pass the name of the file as an argument, which is highlighted below -
m_dump /wload/baot/home/baotasa0/UKRB_UKBE/sandboxes/EXTRACTS/UK/RB/UKBA/ukrb_ukba_pbe_acq/dml/ukrb_ukba_acnt_bde27_src.dml bdfo27m_a016_19122014_V1.dat | head -35
This should give me something similar to what is mentioned below -
Record 1:
I need to extract the bdfo_run_date and display it...
Any help will be greatly appreciated !
Thank you in advance
Moderator's Comments:
Added code tags, changed color to red. Please make sure we can read your posts.
Last edited by jim mcnamara; 06-27-2017 at 09:36 AM..
This request is different from the one in post#1. You didn't give us any hint on what might go wrong with your approach. The head -35 obviously prints mere 29 lines. IS anything ELSE going wrong? SHOULD this give you something similar, or DOES it?
Thank you RudiC and bakunin, but it did not solve my problem
Hello both,
Thank you for writing back, the last line i.e. head -35 should return with a record like I am mentioning below - Record 1:
which is of 35 lines and constitues to first record of the file we are trying to read using m_dump, I need to place the file name using command line and as per Bakunin's suggestion I tried using below code but it did not work -
Once this command is executed, I need to take out bdfo_run_date 41991 to display it...
Neither of my questions has been answered, none of my suggestions was applied, helpful info was not supplied. Instead of focusing on one problem (specified in the first post), you are broadening the operating field and introduce new errors. In your last post, there are at least two syntactical errors: spaces around the equals signs when assigning shell variables, and single quotes around the variables preventing them from being expanded. No surprise it doesn't do what you expect.
Unless you supply info enabling people to help you, I'm afraid I can't help further.
Hi,
I have the script below. When i assign SSH_COMMAND to "ssh -o ConnectTimeout=2 ${SERVER} ${AS_SUDO} ${COMMANDS}" and then execute it as ${SSH_COMMAND} I get the following error:
ssh: Could not resolve hostname sudo: Name or service not known
ssh: Could not resolve hostname sudo: Name or... (3 Replies)
I have the following script, and I want to assign the output ($10 and $5) from awk to N and L:
grdinfo data.grd | awk '{print $10,$5}'| read N L
output from gridinfo data.grd is: data.grd 50 100 41 82 -2796 6944 0.016 0.016 3001 2461. where N and L is suppose to be 3001 and 100. I use... (8 Replies)
Hi,
I have the following command that lists all the .o files from all the directories except of vwin (which I don't want it)
for i in `ls -d */*.o|awk '$0 !~ "vwin"'`; do echo $i; done
The result is something like that
dir1/file1.o
dir1/file2.o
dir2/file3.o
etc.
So, I want to create a... (9 Replies)
Code
set -x
STATUS="0"
echo $STATUS
for i in `ls -ltr Report*|awk '{ print $9 }'`
do
if
then
flg = "`head -1 "$i" |cut -c 31-33`"
echo `head -1 "$i" |cut -c 31-33`
echo $flg
if
then
echo "having Fun"
STATUS="2"
else
echo "no Fun"
fi
fi (2 Replies)
Hi all,
Hereby wish to have your advise for below:
Main concept is
I intend to get current directory of my script file.
This script file will be copied to /etc/init.d.
A string in this copy will be replaced with current directory value.
Below is original script file:
... (6 Replies)
Dear All,
we have a command output which looks like :
Total 200 queues in 30000 Kbytes
and we're going to get "200" and "30000" for further process. currently, i'm using :
numA=echo $OUTPUT | awk '{print $2}'
numB=echo $OUTPUT | awk '{print $5}'
my question is : can I use just one... (4 Replies)
Hi ,
I would like to assign command (with pipe) output to a variable. The code is as follows. The goal of the code is to get the last folder folder with a particular name pattern.
myDate=`ls | grep 2009 | tail -1`
echo "myDate=" $myDate
However, in the presence of the pipe, the code... (3 Replies)
Hi,
I am new to UNIX Scripting. I have been trying to use the CUT command to retrieve part of the header from a file and assign it to a variable. I have tried searching a lot, but I am still unsuccessful.
Sample Header: HJAN BALANCE 20090616
I need to retrieve the date here, which always... (10 Replies)
Hi
I am trying to write a function that needs to be able to assign the last run shell command to a variable. The actual command string itself not the exit code of the command.
I am using the bash command recall ability to do this as follows:
alias pb='ps | grep ash' ... (3 Replies)