Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0

    Exclude executable file when using mv scripted command?


    Hi all,

    New to the forums and new to UNIX/LINUX so please bare with me on this.

    I am an administrator of Oracle Financials and have just started to use Putty to log in. My knowledge of Unix is minimal. I have created an executable file which prefixes the name of files, in a particular dir, containing *BSP* with 'DL_'. It contains this script:

    for f in *BSP*;do mv $f $(echo "DL"_$f);done

    Unfortunately, this executable filename is called BSPRECEIPTCHANGE, so also gets prefixed with DL_.

    Apart from renaming it, is there any way I can exclude this file from being renamed along with the others?

    Many thanks for your help (and patience understanding/deciphering my question) ,

    Scott
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,198
    Rep Power
    17
    kybo
    Code:
    for f in *BSP*
    do 
    case $0 in *RECEIPTCHANGE) continue;; esac
    mv $f DL_$f || exit 1
    done
    exit 0
    working on Solaris[5-9], preferred languages french and C.
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0
    Originally Posted by guggach
    kybo
    Code:
    for f in *BSP*
    do 
    case $0 in *RECEIPTCHANGE) continue;; esac
    mv $f DL_$f || exit 1
    done
    exit 0
    Hi Guggach,

    Thanks for responding. I knew the easy solution would be to change the filename but that doesn't help me learn the code. Although I've not seen/written this code before I can kinda follow it through.

    Many thanks for sharing your knowledge,
    Scott
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,198
    Rep Power
    17
    hello kybo

    sorry for little mistake, note the diff -yesterday it was late ((
    Code:
    for file in *BSP*
    do 
    case $file in *$0) continue;; esac
    mv $file DL_$file || exit 1
    done
    exit 0
    make your life easy, avoid the use of one-char-var-name, suppose
    you have to change that 'f' in a big source file ..... ha ha ha.
    working on Solaris[5-9], preferred languages french and C.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0
    Thanks for the update - I hadn't had chance to try your script so I was unaware of a problem with it.

    I'm hoping to put it to the test later today.

    Thanks again,

    Scott
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0
    Originally Posted by guggach
    hello kybo

    sorry for little mistake, note the diff -yesterday it was late ((
    Code:
    for file in *BSP*
    do 
    case $file in *$0) continue;; esac
    mv $file DL_$file || exit 1
    done
    exit 0
    make your life easy, avoid the use of one-char-var-name, suppose
    you have to change that 'f' in a big source file ..... ha ha ha.
    I can't seem to get it to work. It prefixes the files with 'DL_', as needed, but it still prefixes the executable file.

    Any suggestions???

    Thx,
    Scott
  12. #7
  13. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0
    Originally Posted by kybo
    I can't seem to get it to work. It prefixes the files with 'DL_', as needed, but it still prefixes the executable file.

    Any suggestions???

    Thx,
    Scott
    I added echo to the script and it appears that the $0 variable is returning this: ./BSPNAMECHANGE (The chars ./ was what I used to run the file). Is there any way to remove this, which may fix my problem?

    Thx,
    Scott
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,198
    Rep Power
    17
    The chars ./ was what I used to run the file). Is there any way to remove this, which may fix my problem?
    . dot and / slash in sh-scripts are literals - no special meaning - so that's sure NOT the problem.
    to purge ./ use basename - try man pages for it.
    i tried the scripts (last version), for me it works perfectly using /bin/sh
    working on Solaris[5-9], preferred languages french and C.
  16. #9
  17. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0
    OK, I'll figure out what man pages are (told ya I'm a newb, lol) and give it a look see. I'll then try to put basename into the script and see what happens.

    Thanks again for your help - very much appreciated.

    Scott
  18. #10
  19. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jul 2004
    Location
    Middle Europa
    Posts
    1,198
    Rep Power
    17
    scott why you don't read what i wrote?
    basename will change nothing!!!
    so, post your script.

    man is an unix cmmd : print on terminal the MANual pages of cmmd 'x'
    so: man ls
    will print on terminal the MANual pages of 'ls'
    Last edited by guggach; August 17th, 2010 at 09:52 AM.
    working on Solaris[5-9], preferred languages french and C.
  20. #11
  21. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0
    I'm sorry, but I thought I had!!

    I now know what man pages are and have looked at 'man basename'. Apologies if my incompetence is frustrating you, it's confusing/bugging the hell outta me!!

    Why tell me to try basename, then tell me in your next post that it ain't gonna do a thing

    I'm struggling to incorporate this into a working script. Will keep trying to solve it before I post what script I currently have.

    Appreciate your input, as always.

    Scott
  22. #12
  23. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0
    The closest I have come so far is:

    echo "Running $local_file"
    local_file='basename $0';
    for file in *BSP*
    do
    case $file in *$0)continue;; esac
    mv $file DL_$file || exit 1
    done
    exit 0;

    This is still prefixing the execuable file, though.
    So I'm probably not close at all, eh?

    Thanks,
    Scott
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Mar 2006
    Posts
    2,632
    Rep Power
    1811
    You have a few things 'out of whack' in pursuing this method, try:

    Code:
    local_file='basename $0';
    echo "Running $local_file"
    for file in *BSP*
    do
    case $file in $local_file)continue;; esac
    mv $file DL_$file || exit 1
    done
    exit 0;
    Note I swapped the order of the first two lines (not really needed) as you were doing an echo of the variable before assigning it a value. Then in the case statement we put in this variable (instead of the *$0), which will be the plain script name - so comparisons with the filenames returned by the directory listing will work.
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  26. #14
  27. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0
    Hey Simon,

    Thanks for your input and your explanations - very easy to understand what you have done and why.

    However, it still prefixed this filename (BSPRECEIPTNAMECHANGE).

    The code below, copied from vi is the same (I can't see any differences!):

    local_file='basename $0';
    echo "Running $local_file"
    for file in *BSP*
    do
    case $file in $local_file)continue;; esac
    mv $file DL_$file || exit 1
    done
    exit 0;

    When I ran it, it didn't give me the filename (from the echo statement) either:
    $ ./BSPRECEIPTNAMECHANGE
    Running basename $0

    I assumed it should have said:
    $ ./BSPRECEIPTNAMECHANGE
    Running BSPRECEIPTNAMECHANGE

    This is really frustrating, now. It's all good practice, tho. LOL

    Scott
  28. #15
  29. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2010
    Posts
    11
    Rep Power
    0
    Guggach, Simon,

    Thanks for all your hard work and help on this. After a bit of research I have noticed I was using the wrong single quotes around the basename statement

    I replaced the standard ' with a ` and hey presto, it worked.

    Told you I was new to this game

    Big thank you for your patience.

    Much appreciated,
    Scott
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo