i am trying to change every word that starts with "a" or "b" . if it starts with one of the letters i want to add xx rho the end of the word.
Example : boy ==> boyxx
that what i did so far
PHP Code:
#!/bin/ksh echo "please enter a word: " read word if[ $word -eq a ] || [ $word -eq b ]; then echo "the word is $wordxx" else echo "the word is $word" fi
If "boy" is entered it will never equal 'a' or 'b' and so the expression will always evaluate to false.
Since you are using kshell, the right hand side of an expression in double brackets is treated as a pattern and you can code:
to test if the expansion of $word is a 'b' followed by zero or more characters.
The asterisk (*) must be outside of the quotes or shell will not treat it as a meta character.
If you must, or would rather, use single brackets, then you can code something like this:
Which will take the first character of the value of word and compare it to 'b.' If you try to use pattern characters inside of single brackets the shell will treat them as filename globbing characters and you'll end of with undesired results.
Variable expansion syntax is generally $varname, however when you need to append something to the expanded content, and adding that would form another legitimate variable name ($varnamexx for example), you need to use one of two variations to cause shell to see $varname correctly.
The preferred way putting curly braces round the variable name like either of these:
However, this will usually work too:
If what is being appended is not a legitimate variable name character (a dot forinstance) then you can code something like:
As the shell will stop parsing and recognise the end of the variable name when it encounters a non-name character.
Last edited by agama; 03-03-2012 at 09:24 PM..
Reason: clarification
My purpose was to print out all of name of students in a list.First of all,I created a file name "List" in /home/tuan/Desktop/Shell_programming as below
Tom
Henry
Ben
Linda
Marry
And my script "script" is
#!/bin/sh
path=/home/tuan/Desktop/Shell_programming/List
for student in $path... (3 Replies)
Hi iam new to shell programming. I would like to ask one dought abt the file
handling in unix.
Iam having a file1 as follows:
ASDERFCX1234567890123456
POIUYTRE0098765432123456
BVCXCVBN0955644411111111
File2
ASDERFCX1234567890123456 kill@abc.com ... (8 Replies)
Hi,
Iam new to shell program,
I want to check a file which is having same lines 2 times and i want to display it in a seperate file.
File format is :
AQWERTYU|1234567890
ASDFGHJK|0987654321
ZXCVBNML|1098576453
AQWERTYU|1234567890
I need to take the 1st and 4th lines in the above... (5 Replies)
Could someone please tell me what {} mean when they surround a variable?
For instance,
$FILE = 'basename $1' //what is passed into this script
$BANK = 'dirname $1'
$INFILE = ${FILE}.${BANK}.$$
What does $INFILE contain after this assignment?
Please let me know
Thanks
G (4 Replies)
Provides a menu structure that allows a user to select several options - input a name and address,
lookup a name and address, delete a name and address, and print a formatted report from a text
database (note: this requirement assumes that you will use the program to create a database, though in... (1 Reply)
For what purposes should we use shell
/what are the tasks we can achieve using shell
which is best book to learn shell programming
and will nayone tell me diff between shell programming aand shell scripting?
Thank u in advance. (1 Reply)
I have a fix_table.ksh script that takes a TABLENAME and a date.
So, in jk_table_file.txt I have the tables...one per line, and
in jk_out_file.txt I have the date in the format I need.
The following doesn not 'want' to work in a shell script...
for TABLE in `cat jk_table_file.txt`; do
... (2 Replies)