How read the name of present folder into a variable???


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How read the name of present folder into a variable???
# 1  
Old 04-04-2010
How read the name of present folder into a variable???

Dear all,

Now I have a bunch of files need to be renamed. For instance, I have ten files in a folder with a name 'olefin', and I would like to change all the ten files name into 'olefin01,olefin02,...,olefin10'. I suppose it can be done with the command 'pwd'. However, the command 'pwd' will give the full path of the present folder, /home/study/olefin as an example. The question is how to pick up the folder name 'olefin' from the full path?

I'm not an English native speaker. I hope I have already made me clear here.

Thank you in advance.

Zhen
# 2  
Old 04-04-2010
Try myfolder=`pwd`
# 3  
Old 04-04-2010
Hello figaro,

`pwd` will set the full path to the variable, not the name. How can I cut down the path and only leave the folder name? thanks
# 4  
Old 04-04-2010
Something like this :
Code:
A=/home/study/olefin
B=${A##*/} # to delete the longest correspondance of */ at the beginning of $A
echo $B

# 5  
Old 04-04-2010
to keep the name of file, use command basename

Code:
basename $(echo $PWD)

# 6  
Old 04-04-2010
Yes, I overlooked the requirement you had. You can still do A=`pwd` to fetch the current directory in frans's example.
# 7  
Old 04-04-2010
Thanks you guys, the functional word 'basename' is what I really need. Thanks!
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to replace old date with current date dynamically in multiple files present in a folder

I am trying to work on a script where it is a *(star) delimited file has a multiple lines starts with RTG and 3rd column=TD8 I want to substring the date part and I want to replace with currentdate minus 15 days. Here is an example. iam using AIX server $ cat temp.txt RTG*888*TD8*20180201~... (1 Reply)
Discussion started by: Shankar455
1 Replies

2. Shell Programming and Scripting

Print lines present in first that match second variable. And ones that does not exist in second.

I have multi line input(var1) and reference(var2) variables. How to capture lines not present in var2 but present in var1? How to capture lines present var2 but not in var1? # configuration from server var1=""" Custom JAX-RS Custom Shared Web 2.0 """ # required configuration... (6 Replies)
Discussion started by: kchinnam
6 Replies

3. UNIX for Dummies Questions & Answers

Adding variable value in the begining of all lines present in a file.

I am getting the varible value from a grep command as: var=$(grep "Group" File1.txt | sed 's/Group Name*//g;s/,//g;s/://g;s/-//g') which leaves me the value of $var=xyz. now i want to append $var value in the begining of all the lines present in the file. Can u please suggest? Input file: 1... (10 Replies)
Discussion started by: rade777
10 Replies

4. Shell Programming and Scripting

How to copy all the contents of a list of files present in a folder to a particular file?

Hi All, I want to copy all the contents of a list of files in a folder to a particular file. i am using following command: cat dir/* >> newFile.txtIt's not working. Could you please help? Thanks, Pranav (3 Replies)
Discussion started by: Pranav Bhasker
3 Replies

5. HP-UX

Lost Read permission on my folder

Hi I am a normal user on a HP-UX system which is meant for a large group. There are few directories which I think i am owner of. (Name of these directories is same as my username, and I usually have all the permissions in these directories). I was trying to give read and execute... (2 Replies)
Discussion started by: grvs
2 Replies

6. AIX

What is mknod file present in /etc folder in AIX server used for ?

Hi Guys, On my AIX server , I have this file "mknod" present in the /etc/ directory. When i try opening it , I dont find any ascii characters. It shows some encryption/binary format which is not readable. Is it any executable ? what is the purpose of having this file in etc folder? what if... (2 Replies)
Discussion started by: DBTuner
2 Replies

7. Shell Programming and Scripting

How to check the variable is present in array or not ?

Hi , I am trying to check wether the variable is present in the array. please see the below code .when ever i do this its taking only the first value of the array . please advise. ###Code Snnipet ### #!/bin/ksh set -xv if ]; then echo " you have Specified the ORG ID - $1 " ... (1 Reply)
Discussion started by: padhu.47
1 Replies

8. Solaris

WARNING: filename <not present on Read Only file system>+pkgadd error

Hi when trying to install the package initially that i have created on to the target host, i am getting error as below for all the files/directories during pkgadd. WARNING: filename <not present on Read Only file system> ........... ........... and so on. When i do the second attempt to... (1 Reply)
Discussion started by: kiran.zamre
1 Replies

9. Shell Programming and Scripting

Why does this only read the one folder?

for j in folder1 folder2 folder3 folder4 folder5 do find /tmp/$j -type f -newer /tmp2/newer.txt -exec cp {} /thisfolder1/ \; done. this only reads from folder1 and not the other folders. What's the problem here? (3 Replies)
Discussion started by: bbbngowc
3 Replies

10. Shell Programming and Scripting

read from folder

Collegues I have a number of files in a folder. Each file I would like to exicute one shell script . How to do it in shell With tanks and regards Jaganadh.G (2 Replies)
Discussion started by: jaganadh
2 Replies
Login or Register to Ask a Question