![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Development Releases: Linux Mint 4.0 Beta "Fluxbox", 4.0 Alpha "Debian" | iBot | UNIX and Linux RSS News | 0 | 01-04-2008 12:00 PM |
| Explain the line "mn_code=`env|grep "..mn"|awk -F"=" '{print $2}'`" | Lokesha | UNIX for Dummies Questions & Answers | 4 | 12-19-2007 10:52 PM |
| variables don't work for inline "su" script | joekreif | UNIX for Advanced & Expert Users | 3 | 04-18-2007 01:30 PM |
| how could i make a program mixed with many "|", "<" and ">" | strugglingman | High Level Programming | 2 | 04-29-2006 05:11 AM |
| No utpmx entry: you must exec "login" from lowest level "shell" | peterpan | UNIX for Dummies Questions & Answers | 0 | 01-18-2006 01:15 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
How to omit "./" store in variables
Good Morning All,
I did a find command to search for files and stored it in a variable. I then will use the variable to get the file name and "get" it from another server (using ftp). The problem I have is, filenames are stored with "./" in the variable. when I try to get it, I get an error because "./" does not work in the other server i.e. windows NT. How do I just extract the filename without the "./" as stored in the variables. Example : Contents of FILES variable ./test.txt ./process.txt ./order.txt I only want to get values of $FILES without "./". Thanks a lot! |
| Forum Sponsor | ||
|
|
|
#2
|
||||
|
||||
|
Add this to your script.
Suppose VARIABLE holds all the filenames that came out of the find. Code:
RESULT=`echo $VARIABLE | sed -e 's/\.\///g'` Havn't tested it tho'. Vino |
|
#3
|
|||
|
|||
|
it worked!
Thank you very much!!!! |
|
#4
|
|||
|
|||
|
Code:
RESULT=`echo basename $VARIABLE` |
|
#5
|
|||
|
|||
|
what is a basename? a built in unix function?
|
|
#6
|
||||
|
||||
|
basename is a external command like sed. However:
RESULT=`basename $VARIABLE` is the syntax. With modern shells, you can use builtins to do this: x=${x#./} |
|
#7
|
|||
|
|||
|
Thanks!
Is it also the same if I do : x=${x#*./}? Another curios question. In processing variables, is it always a good practive to enclosed it with curly braces? Thanks a lot! Joseph ps. What is a good unix programming book |
|||
| Google The UNIX and Linux Forums |