{} in shell programming


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting {} in shell programming
# 1  
Old 09-28-2006
{} in shell programming

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
# 2  
Old 09-28-2006
See below ....

$vi a.sh
ab=$(pwd)
echo " "
echo "Current working directory is $ab"
FILE=$(basename $ab)
echo "FILE returns $FILE "
echo " "
ab=$(pwd)
echo "Current working directory is $ab"
BANK=$(dirname $ab)
echo "BANK returns $BANK"
echo " "

INFILE=${FILE}.${BANK}.$$
echo $INFILE


dam@athena:~$ ./a.sh

Current working directory is /home/dam
FILE returns dam

Current working directory is /home/dam
BANK returns /home

dam./home.11937




Not sure what you are trying to achieve...

I think what you probably wanted was

/home/dam.11937
# 3  
Old 09-28-2006
{} is used for building strings.
Code:
FILE = 'basename $1'

the above line of code is taking first parameter passed to this script as argument.what basename command will do here is if you have given the filename with path like /abc/dir1/dir2/filename then the
Value of FILE that is $FILE will have value "filename".
Code:
BANK = 'dirname $1'

the above command will remove the filename and assign path of file to BANK.
BANK will be "/abc/dir1/dir2/"
Code:
INFILE = ${FILE}.${BANK}.$$

Now the INFILE will have value "filename./abc/dir1/dir2/.3456"
here $$ gives the process id. in unix each command will run as a process and generates id.and value of $$ may differ in each run.
# 4  
Old 09-28-2006
Wow does this sound like a homework question.

What do you notice:

THIS=that
$ echo $THIS1
$ echo ${THIS}1
# 5  
Old 09-28-2006
#!/bin/bash
X=ABC
echo "$Xabc"

THis gives no output. What went wrong ? The answer is that the shell thought that we were asking for the variable Xabc, which is uninitialised. The way to deal with this is to put braces around X to seperate it from the other characters. The following gives the desired result:
#!/bin/bash
X=ABC
echo "${X}abc"

------------------

I think that it will clear your doubt.
still you are not getting ...pls give full details so that we can give a solution of same

Thanks
Ckanth
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell Programming

Hi, I am using two files - one file contains list of service name , other file contains commands for each of these service name . I have to read each service name and check this string in 1.cfg file , if it exists , then i have to read another file (commands file ) and take the string and... (2 Replies)
Discussion started by: santhoshks
2 Replies

2. UNIX for Dummies Questions & Answers

Shell script to read lines in a text file and filter user data Shell Programming and Scripting

sxsaaas (3 Replies)
Discussion started by: VikrantD
3 Replies

3. Shell Programming and Scripting

Shell programming

Hi every one,i am new to unix.Can any one tell me about shell programming.. (1 Reply)
Discussion started by: martina100011
1 Replies

4. Shell Programming and Scripting

SHELL PROGRAMMING

Using shell scripting, implement ‘scan.sh' that scans the file system recursively starting from current working directory and generates the file ‘index.txt' that contains a line for each file (or directory) with following fields in tab separated format: 1. The full path of the directory... (1 Reply)
Discussion started by: kranthikiran
1 Replies

5. Shell Programming and Scripting

shell programming

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)
Discussion started by: nivas
8 Replies

6. Shell Programming and Scripting

Shell programming

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)
Discussion started by: nivas
5 Replies

7. Shell Programming and Scripting

shell programming

I want notes for learning Shell programming (2 Replies)
Discussion started by: Neha Agarwal
2 Replies

8. Shell Programming and Scripting

Shell Programming?

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)
Discussion started by: shrikrishna
1 Replies

9. UNIX for Dummies Questions & Answers

Shell Programming Help

Hi, I am new to shell programming, and hve been given a request to write a shell script. Is there any good places to go to see examples of how to write shell programming scripts? Thanks (4 Replies)
Discussion started by: mec585858
4 Replies

10. UNIX for Dummies Questions & Answers

Shell Programming

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)
Discussion started by: JWK1
2 Replies
Login or Register to Ask a Question