Page 3 of 4 FirstFirst 1234 LastLast
Results 21 to 30 of 37

Thread: What is wrong with this TINY bash command/script?

  1. #21
    Join Date
    May 2006
    Location
    Alberta, Canada
    Beans
    639
    Distro
    Ubuntu 15.04 Vivid Vervet

    Re: What is wrong with this TINY bash command/script?

    I think I am beginning to wrap my head around it. It's not terribly difficult really, once some of the fundamentals are understood. But I think that's where most people get lost, the fundamentals don't always seem particularly intuitive. I think this is why scripting languages like javascript are more easily understood.

    I don't have time to reply at length just now, but I will perhaps later. It turns out that Rochelle's rehearsal got moved into Edmonton (we're actually a little ways out of Edmonton), so I have a much busier day ahead of me than I originally planned.

    Thank you very much for your explanation. I'll have more questions for you soon enough
    • Note To Self:gksudo is safer than sudo for graphical apps!

  2. #22
    Join Date
    Aug 2006
    Beans
    375
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: What is wrong with this TINY bash command/script?

    Than I'm glad you understood the most if not all of this.

    And I'm happy to answer your questions if I can

  3. #23
    Join Date
    Sep 2006
    Beans
    2,914

    Re: What is wrong with this TINY bash command/script?

    Quote Originally Posted by em3raldxiii View Post
    I am attempting to rename multiple .m4b files to .m4a files (because xmms doesn't know how to handle m4b even though it's identical to m4a as far as I know).
    hi
    just want to rename .m4b to .m4a right?
    here's an alternative, in Python

    Code:
    >>> import os
    >>> for files in os.listdir(os.getcwd()):
    ... 	path,ext = os.path.splitext(files)
    ... 	if ext == ".m4b":
    ... 		try:
    ... 			os.rename(i, path + ".m4a")
    ... 		except Exception,e:
    ... 			print e
    spaces taken care of.
    cheers

  4. #24
    Join Date
    May 2006
    Location
    Netherlands
    Beans
    561
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: What is wrong with this TINY bash command/script?

    Quote Originally Posted by em3raldxiii View Post
    Now, when I do a man -k xargs, all it gives me is this: - build and execute command lines from standard input ... um ... yeah ... okay .... that explains everything! I can see the light!! It all makes SO much sense when you put it THAT way ... not. LOL, I suppose I am REALLY showing off my Newb-ness hey?
    So why not try `man xargs` and read the whole thing?
    Quit the man page by pressing q.
    (\ /)
    (O.o)
    (> <)

    This is Bunny. Copy Bunny into your signature to help him on his way to world domination.

  5. #25
    Join Date
    May 2006
    Location
    Netherlands
    Beans
    561
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: What is wrong with this TINY bash command/script?

    Quote Originally Posted by nereid View Post
    Code:
    #!/bin/bash
    find -type f -print0 | xargs -0r rename 's/(.*)\.m4b$/hpcos$1\.m4a/' *.m4b
    Save it for example as my_rename.sh, chmod +x my_rename.sh and call it like this: ./my_rename.sh /location/of/your/directory
    Hi Nereid,

    Have been away for a couple of days so could not reply. I'm afraid the script doesn't work, because it's not catching the used argument and using it in the find command. I think it needs to be:

    Code:
    #!/bin/bash
    find -type f -print0 $1 | xargs -0r rename 's/(.*)\.m4b$/hpcos$1\.m4a/' *.m4b
    The $1 in the find command catches the script's first argument.

    Ivo
    (\ /)
    (O.o)
    (> <)

    This is Bunny. Copy Bunny into your signature to help him on his way to world domination.

  6. #26
    Join Date
    Aug 2006
    Beans
    375
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: What is wrong with this TINY bash command/script?

    I do know that $1 is used for the argument but I discovered that find works without it. Just try it out using only the find command

    Code:
    #!/bin/bash
    
    find -type f
    Save the script and execute it with an directory as argument. You should get a list of all files contained in the target directory.

  7. #27
    Join Date
    May 2006
    Location
    Netherlands
    Beans
    561
    Distro
    Ubuntu 7.10 Gutsy Gibbon

    Re: What is wrong with this TINY bash command/script?

    Quote Originally Posted by nereid View Post
    I do know that $1 is used for the argument but I discovered that find works without it. Just try it out using only the find command

    Code:
    #!/bin/bash
    
    find -type f
    Save the script and execute it with an directory as argument. You should get a list of all files contained in the target directory.
    Tried it before I posted yesterday, and tried your suggested code again. Sorry, doesn't work for me

    In ~/tmp:
    Code:
      12:07:09 ifokkema@5-HKG-02-0098:tmp$ ./test .
    ./test
      12:08:45 ifokkema@5-HKG-02-0098:tmp$ ./test ~/www
    ./test
    (\ /)
    (O.o)
    (> <)

    This is Bunny. Copy Bunny into your signature to help him on his way to world domination.

  8. #28
    Join Date
    Oct 2005
    Location
    Copenhagen
    Beans
    206

    Re: What is wrong with this TINY bash command/script?

    Hey everybody. I hope em3raldxiii will forgive me for using this thread for this question, it is on another matter so please everyone do answer if you can but not at the expence of focus on the original subject so I don't become guilty of thread hijacking. But since there seems to be so many commandline/script competent people here it seems like an apportunity. I was wondering, do any of you know if it, in a bash script, is possible to replace one of the script commandline arguments, say $2. I'm asking this beacuse I want to implement a few long options ala --version, but the bashinternal getopts don't handle them and I would rather not use external commands. If this is possible I could just loop thorugh $@ and test if there was a long option and then replace it with a short, and then use getopts.

  9. #29
    Join Date
    Aug 2006
    Beans
    375
    Distro
    Ubuntu 11.04 Natty Narwhal

    Re: What is wrong with this TINY bash command/script?

    @ifokkema
    This is really strange. On my system this is working all right.

    @TLE
    Sure, as far as I know, you can replace $2 with any value. It is nothing else than a simple variable.

  10. #30
    Join Date
    Oct 2005
    Location
    Copenhagen
    Beans
    206

    Re: What is wrong with this TINY bash command/script?

    @nereid
    But how do I acces it. If it were an ordinary variable, like say $input I would do:
    Code:
    unset input
    input="New value"
    But I can't do that for $2

Page 3 of 4 FirstFirst 1234 LastLast

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
  •