bash bleg

Oct. 13th, 2006 07:23 pm
gusl: (Default)
[personal profile] gusl
If you have a 'file' variable containing a whole path the a file, how do I get just its filename?

How does one iterate through space-separated strings in a big string? (I suspect this uses 'split' to create an array of strings)

What is a good bash scripting reference? http://justfuckinggoogleit.com/ is not the answer I'm looking for.

(no subject)

Date: 2006-10-14 12:42 am (UTC)
From: [identity profile] bhudson.livejournal.com
basename, dirname, and the perl package of the same name are your friends. I often also write a 'noext' perl script that I can email you if you want it (strips the last extension).

For (ba)sh, the 'for' command does what you want:
for x in $foo ; do mv $x `basename $x`/mainfile ; done
or whatever.

All my scripting I learned from man pages and looking at other sh scripts.

February 2020

S M T W T F S
      1
2345678
9101112131415
16171819202122
23242526272829

Most Popular Tags

Style Credit

Expand Cut Tags

No cut tags