Re: Need some bash scripting assistance

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 10Jun2010 13:51, James Wellnitz <jwellnitz@xxxxxxxxx> wrote:
| Something like this will basically do the "increment target link" part
| (making some big assumptions, doing no error checking, not handling
| wrap-around, etc.):
| 
| cur_link=$(readlink target | sed -e "s#./##")
| cur_number=${cur_link%% *}
| cur_number=${cur_number#0}
| let new_number=cur_number+1
| new_number=$(printf "%02d" $new_number)
| new_link=$(find . -name "${new_number} *")
| ln -sf "${new_link}" target
| 
| Dealing with the leading '0' (zero) accounts for some of odd parts
| (e.g. the printf).

Or, untested, this:

  cur_link=$(readlink target | sed -ne 's/^0*\([0-9][0-9]*\) .*/\1/p')
  next=$(expr "$curlink" + 1)
  next0=$(printf "%02d" "$next")
  set -- "$next "*
  rm target && ln -s "$1" target

which seems a bit shorter.

There's no sanity checking in there, eg that $cur_link is not empty or
that the set command matches exactly one file.

Most particularly, using find to get filenames is rather heavyweight and
wordy and flakey in the face of weird filenames.

Cheers,
-- 
Cameron Simpson <cs@xxxxxxxxxx> DoD#743
http://www.cskk.ezoshosting.com/cs/

If I had thought about it, I wouldn't have done the experiment.
The literature was full of examples that said you can't do this.
      --Spencer Silver on the work that led to the unique adhesives
        for 3-M "Post-It" Notepads.
-- 
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines

[Index of Archives]     [Older Fedora Users]     [Fedora Announce]     [Fedora Package Announce]     [EPEL Announce]     [EPEL Devel]     [Fedora Magazine]     [Fedora Summer Coding]     [Fedora Laptop]     [Fedora Cloud]     [Fedora Advisory Board]     [Fedora Education]     [Fedora Security]     [Fedora Scitech]     [Fedora Robotics]     [Fedora Infrastructure]     [Fedora Websites]     [Anaconda Devel]     [Fedora Devel Java]     [Fedora Desktop]     [Fedora Fonts]     [Fedora Marketing]     [Fedora Management Tools]     [Fedora Mentors]     [Fedora Package Review]     [Fedora R Devel]     [Fedora PHP Devel]     [Kickstart]     [Fedora Music]     [Fedora Packaging]     [Fedora SELinux]     [Fedora Legal]     [Fedora Kernel]     [Fedora OCaml]     [Coolkey]     [Virtualization Tools]     [ET Management Tools]     [Yum Users]     [Yosemite News]     [Gnome Users]     [KDE Users]     [Fedora Art]     [Fedora Docs]     [Fedora Sparc]     [Libvirt Users]     [Fedora ARM]

  Powered by Linux