ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Hi, this needs to be done with sed and ideally needs to do this without creating temp files.
TMPDIR="/whatever/you/want/"
This directory eventually gets some tar files written to it, these tar's are then stripped of their directories, I also need to remove whatever the $TMPDIR is.
e.g
/whatever/you/want/importantfiles.tar.gz
becomes importantfiles
I can strip everything ($TMPDIR/*.tar.gz | sed 's/.tar.gz//g') but the directory variable - any ideas? I know this is a real challenge and I'm upto using alternatives to sed (e.g tr or awk or something similar, not perl).
I like the look of the basename stuff, it's for a script and I'd like to allow the users to specify their own temp directories, so although having a.directory could be problematic, it's the most elegant solution and problems could be put down to user error (I'll write some error checking code).
Actually, I have a small confession to make; the reason I was getting directories in the first place was due to bad coding on my part. I did 'ls -a $DIR/*' and was concerned when the dir's were displayed when really the quickest solution would just be to do 'ls -a $DIR' and then my sed statement to remove the tar.gz. (it's just a standard for loop where each tar has a different action).
Thanks anyway, this basename stuff will probably be used elsewhere as I have numerous similar lines which aren't using ls.
Actually, I have a small confession to make; the reason I was getting directories in the first place was due to bad coding on my part. I did 'ls -a $DIR/*' and was concerned when the dir's were displayed when really the quickest solution would just be to do 'ls -a $DIR' and then my sed statement to remove the tar.gz. (it's just a standard for loop where each tar has a different action).
for file in "$dir"/* ; do
name="${file##*/}"
name="${name%%.*}"
echo "$name"
done
As for temporary directories, TMPDIR is the standard variable for the top-level temporary directory (usually /tmp). Well-behaved programs should pay attention to TMPDIR.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.