This is a very simple function called i_upper_case , you can probably guess what it does. The backslash at the end of the echo line is a UNIX feature that allows a command line to be continued on the next line. It tells the system to ignor the next character - in this case the newline. Note that it gets its input argument from a passed parameter ($1). So to make use of this function within a script you simply need to call it with an argument as follows:
So when I created a function as follows
And then do the following SH script
The function works correctly. Is there any danger concerning this variable not getting set correctly by calling it this way?
...
The function works correctly. Is there any danger concerning this variable not getting set correctly by calling it this way?
Let's try it out
Remember the $1 from the example you found? You can refer to the function arguments using $1 - $9. When you use $TEST in your function it isn't reading a parameter - it's reading an outside variable definition. By not using $1 you actually lose some functionality.
The other thing of some interest is the assignments you make using cat /somefile. First off, the cat is not necessary - but second, and more importantly be aware that assigning this data to a variable has a compressing effect.
Wow Dude u just blew my mind...If what I think you said is what you actualy said WOW can i go places.
First of about using cat:
Quote:
echo -==Mainframe System Date Time `cat $RKEM_LOG"rkem_mainframe_system_date_time.txt"`==- >> $RKEM_LOG$TEST
What I am trying to do here is take the data that is in the variable $RKEM_LOG and append the "rkem_mainframe_system_date_time.txt" to create a full path. Is this where you mention my improper use of cat or was it here:
This is where I read what is in this file which is the text string that makes up the begining of the path. I am doing this so that I can move these scripts around and not have to recode. Should I be using syntax that looks like this:
Here rkem_log_dir is actualy a file that contains the desired text. The goal again was that if i needed to change path locations I would only have to change the file and the one set of code that sets the path variables...
What does the < stand for?
Also I did not see what you ment by whey you said that CAT causes compresion. Both outputs looked the same to me...
As for the variables...
Quote:
By not using $1 you actually lose some functionality.
Does the $1 indicate the first variable?...Meaning that if I had a second variable then I would use $2?
If what I am saying is true then it should look something like this
OLD CODE
NEW CODE
And to call this I would do something like this
Am I just totaly out of my mind or did I actualy figure out something?
Wow Dude u just blew my mind...If what I think you said is what you actualy said WOW can i go places.
First of about using cat:
What I am trying to do here is take the data that is in the variable $RKEM_LOG and append the "rkem_mainframe_system_date_time.txt" to create a full path. Is this where you mention my improper use of cat or was it here:
This is where I read what is in this file which is the text string that makes up the begining of the path. I am doing this so that I can move these scripts around and not have to recode. Should I be using syntax that looks like this:
Here rkem_log_dir is actualy a file that contains the desired text. The goal again was that if i needed to change path locations I would only have to change the file and the one set of code that sets the path variables...
What does the < stand for?
Also I did not see what you ment by whey you said that CAT causes compresion. Both outputs looked the same to me...
If you check the manpage for cat you'll see that it's used to concatenate files. When you're making variable assignments you don't need to use cat. Just go ahead and do this:
I made the comment about the compression because I mistakenly thought you were trying to get the data in the files rather than assigning the names of the files. Since we brought it up, though check out the actual file listing versus the output of the variables they were assigned to. In both instances the linebreaks were removed and the whole file ended up on one line. This could be a pitfall if you attempted to do a sed or grep on that data.
I threw an extra '/' character in the lines with '$RKEM_LOG/$TEST' under the assumption that the variables are directory name and file name.
Regarding the backticks `` or $() - you'll need to sed s#/bin/sh#/bin/bash#g my previous posts where I used the $() as I don't recall this being available in standard Bourne shell. Go with the `` for portability.
Quote:
Originally Posted by jadionne
As for the variables...
Does the $1 indicate the first variable?...Meaning that if I had a second variable then I would use $2?
If what I am saying is true then it should look something like this
OLD CODE
NEW CODE
And to call this I would do something like this
Am I just totaly out of my mind or did I actualy figure out something?
You got it.
The only thing is when you make the call do something like:
or
or better yet combine your variables in the function like this:
OK here goes one more example. Im going to try this but wanted another set of eyes on this.
I have a function that sets the path variables, lets call it THE_PATH. One of the variables is called RKEM_LOG. There is a / embeded at the end of the variable definition. I have another function called RKEM_Mainframe_time. In this function I use the variables $1 and $2. Will this work:
Regarding the use of CAT and seting the variables, I tried the following:
Instead of setting the variable = to the data that was inside the rkem_log_dir file it just set the variable = to the string that was passed in or
This is not necisarily what is going to be in that file
Hello,
im creating a csv file for email reporting on issues.
my problem is that after 'continue' command in if statment in a loop
the new paramter writing into the log doesnt take new line.
timeout 4s zabbix_get -I $ZBX -p $PORT -s $IP -k "system.run"
if ; then
... (3 Replies)
I am fairly new to writing scripts, and have gotten a lot of help from this site in the past with many of the posts.
I have a question/issue with a script I am attempting to write and have a question regarding executing an sql statement inside of a loop (do while). I have in the past written... (1 Reply)
Hello everyone
I was hoping someone could tell me whether I can use a wildcard inside an tcsh if statement.
I am trying to test the argument the user has fed the script and whether it is a .txt file.
The Ides behind it is the following
if (`echo $1` != *.txt) then
echo "wrong... (6 Replies)
Hi
what's the correct way of writing if
1)if "$time_diff" -gt 5
then
echo "killing hung process \n"
fi
2)if test $time_diff -gt 5
then
echo "killing hung process \n"
fi
where -time_diff=$(($Sam - $current_min))
and current_min=`date +%M`
infact both are giving Syntax... (1 Reply)
Please let me know if I can use -F option and - V in a single awk statment. I want to import some comma separated shell variables using -F option and defining some static variables inside awk using -v option. (2 Replies)
I need to validate the special characters of a date (the characters between the year and month & month and day). The data filed is being populated by users and read into the script vi an argument. I want to ensure that the date is a '-' (dash) and not a '/' or '\' (slash).
The every thing I... (3 Replies)
Can someone tell me what exactaly the following command is doing -
pid_cmd="/usr/ucb/ps -axww | /usr/bin/egrep '${SUNMC2OSS_PATH}/SunMC2OSS\.jar.* sunmc2oss\.SunMC2OSS\$' | /usr/bin/egrep -v egrep | /usr/bin/nawk '{print \$1}'"
Is the egrep is to check "sunmc2oss.SunMC2OSS" process inside... (2 Replies)
hello
im working on a project for the iphone to write a termainal based program
we have bsd subsystem installed so have access to most unix command
i have a executable called coordinates, which get the coordinates of the iphone
when this runs it returns to the terminal the text of... (1 Reply)
I am looking to find something in the hour(in field $2) of 03:00:07 and 04:00:07 and 05:00:07 and must contain something in field 4... why doesn't below command work?
I try to use grep .. but since I am running this in loop, it's best I use the awk ..
can someone please advise.. I am pretty... (1 Reply)
hi 2 all,
I'm trying 2 print " ' " in an awk statement but the sign deosn't show.
The only way I came with is 2 declare the ' as a variable and call that variable.
I'm trying 2 do:
awk '{printf("insert into ba_memo_01 values ('%s');",$1)}'
and get the output:
insert into ba_memo_01 values... (7 Replies)