file ext

file ext

Post by harr » Fri, 14 Dec 2001 06:39:21



#!/bin/sh

for file in *
     do
        echo $file # instead of the full file name, i want the extension
only
     done

how to display $file extension only?
thanks

 
 
 

file ext

Post by Chris F.A. Johnso » Fri, 14 Dec 2001 06:57:24



> #!/bin/sh

> for file in *
>      do
>         echo $file # instead of the full file name, i want the extension
> only
>      done

> how to display $file extension only?

If your /bin/sh is POSIX compliant (or you can use bash or ksh):

        echo "${file$##*.}"

Otherwise:
        echo "$file" | sed 's/.*\.//'
or:
        echo "$file" | awk -F\. '{print $NF}'

--
    Chris F.A. Johnson                        http://cfaj.freeshell.org
    ===================================================================
    My code (if any) in this post is copyright 2001, Chris F.A. Johnson
    and may be copied under the terms of the GNU General Public License

 
 
 

1. DOSEMU boot files: ext .EMU work???

According to the /etc/dosemu.conf file :

#    Specify extensions for the CONFIG and AUTOEXEC files.  If the below
#    are uncommented, the extensions become CONFIG.EMU and AUTOEXEC.EMU.
#    NOTE: this feature may affect file naming even after boot time.
#    If you use MSDOS 6+, you may want to use a CONFIG.SYS menu instead.
#
#
EmuSys EMU
EmuBat EMU

However, this doesn't seem to work.  Suggestions??
--

2. Installing autoconf [was: Installing Sablotron...]

3. rm, mv, others barf on #file.ext#

4. C Structure in Shared Memory question.

5. About Z file ext

6. LINUX INSTALATION

7. How do I allow /secure/file.ext, but disallow /cgi-bin/process.cgi/secure/file.ext?

8. Printing problem from Linux to Windoze...HELP PLS!

9. Why does compress produce whatever.ext.Z rather than z/whatever.ext?

10. setting default permission mask for new files on ext[23]?

11. BUG in 0.99 pl 10 with ext file system

12. tar.gz file for Japanese Ext to Linux (0.9.3) 94/1/24 available

13. find a file and output filename without dir spec and ext