Find the answer to your Linux question:
Results 1 to 5 of 5
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Newbie scripting - file extensions..

    Hi There Guru's!

    I am writing a simple script to move application program files between a live and test environment. Each file can have either a .i extension, or a .p and a .r (source and x-coded). The x-coded file goes to a directory which starts with the same two letters, thus:


    Source Name = apvomt.p
    Compile Name = apvotmp.r

    I have managed to create the script which moves the files, provided they are a .p extension, but I now need to check if the extension is a .i

    How do I just pick up the last 2 characters of the filename - can I use CUT, or is there another way?

    Many thanks


  2. #2
    Linux Guru
    Join Date
    Oct 2001
    Täby, Sweden
    Provided you're using bash and not some other shell, there's a syntax for cutting in variables (maybe other shells can do it as well, but I haven't tried, so I don't know how compatible it is). It looks like this:
    echo "$ext"       # This will echo "foo"

  3. #3
    moeh :?
    Either i don't get what yout getting at or you could yield:
    mv *.i ./some_dir_down/

    the ./ means 'relative from the current dir'

    You could also do:
    mv *.i ../some_dir_next_to/
    to move them to the dir next to the current one.

  4. $spacer_open
  5. #4
    Use case:
    case $file in
       *.i)    # code for the .i files
               # blah
               # blah
        *.p)  # code for the .p files
               # blah
               # blah
    ...etc ...

  6. #5
    more info on writing proper scripts: (like scm's) ~>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts