Page 2 of 2 FirstFirst 12
Results 11 to 12 of 12

Thread: Bash script examples

  1. #11
    Moderator KMDave's Avatar
    Join Date
    Jan 2010


    If you want to write a script, then you should be doing the research

    Seriously that is nothing really hard to do nor is it hard to find. Just lay down, enjoy a good night's sleep and start fresh in the morning.
    Tiocfaidh ár lá

  2. #12
    Junior Member cleguevara's Avatar
    Join Date
    Dec 2007


    Quote Originally Posted by vvpalin View Post
    Before i fall asleep can i ask a big favor ... Im probably going to write a firefox update script tomorrow and i was wondering how you could match a givin text string in a file and replace it with whatever you need. Im sure it will support wildcards so i really neednot ask but thats a must.

    Thanks a bunch.
    hint: the command you're looking for is "sed"

    cat inputfile | sed "s/string-to-replace/new-string/g" > outputfile
    (Warning: Don't use the same file for input and output, as '>' will overwrite the file before "cat"ing it)

    I recommend you to review the manpages of sed and google for "regular expressions" (you'll need it for wildcards etc). If sed does funny things you should also check your quotation inside the expressions (string-to-change & new-string). That should do the job...

    I think it's the best way to become comfortable with the basic linux commands like grep and sed (and awk when you want do get really dirty) and of course fiddling with pipes. Second: experiment a bit with very linear scripts (simple sequence of commands to run) and use variables. Third: implement while/for-loops and if-clauses. The last would be to use functions inside the scripts (reduces the size of the script dramatically and it's better to understand and maintain). Your knowledge will grow linear to the complexicity of the problem you want to solve with the script ;-).
    Overall it should not be too time consuming. IMHO a book is not necessary and your learning courve would be gained if you code your scripts from scratch instead of "jumping into the code" (i think that this makes most sense after you got around with the basics)

    @KMDave - sorry I read your comment too late (but I think a little advise is ok).

Page 2 of 2 FirstFirst 12

Posting Permissions

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