LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 08-21-2021, 10:10 PM   #16
elnetotaca
LQ Newbie
 
Registered: Jan 2011
Posts: 16

Original Poster
Rep: Reputation: 0

I will do nd thanks again for the extra info!

Last edited by elnetotaca; 08-21-2021 at 10:11 PM. Reason: non whatsoever.
 
Old 08-22-2021, 10:36 AM   #17
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,804

Rep: Reputation: 1203Reputation: 1203Reputation: 1203Reputation: 1203Reputation: 1203Reputation: 1203Reputation: 1203Reputation: 1203Reputation: 1203
$[arith]
is a deprecated bash-only style.
The new standard for an arithmetic expression is
$((arith))
 
Old 08-23-2021, 04:53 AM   #18
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,899

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
additionally probably I would try to remove that link before [re]creating it. Otherwise it may have "strange" side effects.
 
1 members found this post helpful.
Old 08-24-2021, 12:42 AM   #19
ondoho
LQ Addict
 
Registered: Dec 2013
Posts: 19,872
Blog Entries: 12

Rep: Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053Reputation: 6053
What "strange" side effects? The '-sf' options to 'ln' have never failed me so far.
 
Old 08-24-2021, 12:55 AM   #20
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,868
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
When symlinks to directories are involved, option `-sfn` might be even safer.
 
1 members found this post helpful.
Old 08-24-2021, 12:57 AM   #21
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,899

Rep: Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318Reputation: 7318
Quote:
Originally Posted by ondoho View Post
What "strange" side effects? The '-sf' options to 'ln' have never failed me so far.
That is my paranoid "side". Usually removing requires fewer permissions than this ln. But you are right, probably in a single user environment it is pointless.
 
Old 08-24-2021, 02:48 AM   #22
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,900

Rep: Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023
As Nev' says, existing links pointing to directories can result in unexpected outcomes.

GNU's ln has the -n, or -T options to deal with this situation, but POSIX adherents will need to remove any existing link with rm -f prior to creating a new one to avoid this issue catching them out.

Getting back to OPs original question: I would have used the following for this job:
random_mp3=$( printf "%s\n" *.mp3 | shuf -n 1 )

Last edited by GazL; 08-24-2021 at 02:58 AM.
 
Old 08-24-2021, 08:38 PM   #23
elnetotaca
LQ Newbie
 
Registered: Jan 2011
Posts: 16

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by GazL View Post
As Nev' says, existing links pointing to directories can result in unexpected outcomes.

GNU's ln has the -n, or -T options to deal with this situation, but POSIX adherents will need to remove any existing link with rm -f prior to creating a new one to avoid this issue catching them out.

Getting back to OPs original question: I would have used the following for this job:
random_mp3=$( printf "%s\n" *.mp3 | shuf -n 1 )
Thank you very much.
So far I have NO PROBLEMS whatsoever, so I will stick with it.
but THANK YOU again!!!!!
 
Old 08-25-2021, 02:10 AM   #24
GazL
LQ Veteran
 
Registered: May 2008
Posts: 6,900

Rep: Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023Reputation: 5023
Quote:
Originally Posted by elnetotaca View Post
Thank you very much.
So far I have NO PROBLEMS whatsoever, so I will stick with it.
but THANK YOU again!!!!!
No worries: it's all good.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
generating k permutations of a series and then generating all possible binary trees from them jamesbon Programming 5 09-27-2018 12:42 AM
randomize shuffling of a file with many lines papori Linux - Newbie 6 04-15-2014 12:19 PM
randomize non repeated numbers mystical dervish Programming 10 06-15-2007 04:34 AM
Randomize /etc/motd? lengau Linux - General 4 09-05-2005 11:01 PM
How to randomize Splash Image using Gnome??? thinhla Linux - General 1 07-15-2005 10:39 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration