Results 1 to 3 of 3

Thread: Basic bash scripting help?

  1. #1
    Join Date
    Nov 2008
    Location
    San Francisco, California
    Beans
    389
    Distro
    Ubuntu 12.04 Precise Pangolin

    Basic bash scripting help?

    Hi, I'm trying to use imagemagick to convert a bunch of .jpg files with custom color profiles to .png files without the pesky custom profiles. I believe the command I want is convert x.jpg x.png
    (where x is the name of the file,a numerical value from 001.jpg to 4500.jpg).

    Since there are so many files I want to write a bash script to do this, but I suck at writing in any sort of pseudo-programming language, so I was hoping for some basic pointers on how to repeat this command for each file.

    Thanks!

  2. #2
    Join Date
    Apr 2009
    Location
    Located
    Beans
    236
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Basic bash scripting help?

    If all the pic are in the same folder you could try something like this (untested (and im new to bash scripting so this might not work ) )

    Code:
    # change to the folder where your pics are
    cd '/folder/pics/are/in';
    
    # loop through the folder
    for img in *.jpg; 
    do
    
    # replace the file extension attached to $img with "nothing" (so to create the .png file name correctly)
    newName=${img/.jpg/}; 
    
    convert "$img $newName.png";
    
    done
    'done' is part of the code, not a personal comment

    _
    Last edited by iMisspell; January 1st, 2010 at 09:28 AM. Reason: typo in code, used $ sign to comment out in-stead of #
    |
    --------------------------------------------------------------------------------------------------------
    ~ What was once an opinion, became a fact, to be later proven wrong ~

  3. #3
    Join Date
    Jul 2005
    Location
    Hughenden, Australia
    Beans
    5,100
    Distro
    Ubuntu Mate 20.04 Focal Fossa

    Re: Basic bash scripting help?

    Here's another one just in case you want an alternative, you need to cd to the directory contianing your .jpg images first,
    Code:
    for f in *.jpg; do mv "$f" "${f%.jpg}.png"; done
    EDIT: It's actually pretty much the same command, just condensed a bit. Probably I shouldn't have intruded, sorry for my rudeness.
    Last edited by Herman; January 1st, 2010 at 09:29 AM.
    Ubuntu user since 2004 (Warty Warthog)

Bookmarks

Posting Permissions

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