Re: [OT] Need some bash scripting assistance

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

 



Marko Vojinovic wrote:
> Hi folks! :-)
> 
> This is the story: I have a directory full of files named as:
> 
> 01 Some file
> 02 Some other file
> 03 & yet another file
> 04 etc...
> 
> There is also a symbolic link called "target" pointing to one of them.
> The numbers at the beginning of file names are there so that there is
> some specific ordering of files. What I need is a bash script that
> will determine the name of the file that goes after the one target
> points to, and relink the target to point to that one instead.
> 
> So if target points to "02 Some other file", after executing the
> script it should point to "03 & yet another file". When the target
> reaches the end it should restart from the beginning. Files typically
> have spaces and other escapable characters that should be properly
> taken care of.
> 
> Can anyone point me into the easiest way of doing this?
> 
> What I am actually doing is more complicated, but this step is where I
> am a bit clueless... :-)

If it is the "rotation" part you want help on, I can give you some
suggestions.

You find the name of the linked file with
  find target -printf "%l\n"

You find the new destination for target with
  ls|grep -A1 "$oldtarget"|tail -1

The end-of-list condition can be handled with an additional dummy
file and then an explicit if [ "$newtarget" == "ZZZ_after_the_last" ]
approach. Or you can use a trick like "(ls;ls)|grep -A1 ...".

Is that enough for you to go on?

Take care of the strange characters in filenames, as others have rightly
pointed out.

-- 
   Roberto Ragusa    mail at robertoragusa.it
-- 
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