Re: [OT] Need some bash scripting assistance

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

 



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).

On Thu, Jun 10, 2010 at 12:23 PM, Dale J. Chatham <dale@xxxxxxxxxxx> wrote:
>
> Just to nail the point home, if you have spaces in the name, you must
> put quotes around the name of the variable containing the name.
>
> Or:
>
> FILE="a b c.txt"
>
> cat "$FILE"
>
> cat "a b c.txt"
>
> If it has things like "?", "*", or others, Danger Will Robinson!!
>
> On 06/10/2010 11:14 AM, Roberto Ragusa wrote:
>>
>> 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.
>>
>>
>
>
> --
> Our peculiar security is in the possession of a written Constitution.
> Let us not make it a blank paper by construction."
>
>    --Thomas Jefferson, letter to Wilson Nicholas, 1803
>
> There are four boxes to be used in defense of liberty:
> soap, ballot, jury, and ammo. Please use in that order.
>  -- Ed Howdershelt (Author)
>
> --
> 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
>
-- 
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]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux