LinuxQuestions.org
Review your favorite Linux distribution.
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 06-19-2011, 02:23 PM   #16
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037

I don't think cat is bad when you're working with known files containing known values. It's just unnecessary.

A few follow ups to the above code comments:

Another alternate parameter test...
Code:
if [[ -z $* ]]; then
Even better than basename is this (because it's built-in)...
Code:
echo "Usage: ${0##*/} <value file>"
Exit codes with special meanings

Quoting the left side expression in [[ .. ]] is safe, but quoting the right side expression will change the meaning.
http://mywiki.wooledge.org/BashFAQ/031
http://mywiki.wooledge.org/BashPitfa...g_on_intent.29

Last edited by David the H.; 06-19-2011 at 02:26 PM.
 
Old 06-19-2011, 06:06 PM   #17
tuxdev
Senior Member
 
Registered: Jul 2005
Distribution: Slackware
Posts: 2,012

Rep: Reputation: 115Reputation: 115
Quote:
I don't think cat is bad when you're working with known files containing known values. It's just unnecessary.
It's still bad to use the worst method available, even if it happens to work *this time*. It's just not generally reliable and rather fragile, so you can't use the script for any other input, which kinda defeats a lot of the point of scripting. Bash is already really bad about robust input handling, throwing away the little robustness it does offer is quite likely to bite you back eventually. Like, by deleting all of your data.
 
  


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
[SOLVED] How do you log-in on a "user" only log-in with a wrong or bad password? steelheat Linux - Newbie 2 12-12-2009 09:08 AM
The "Log out" and "Lock screen" actions cannot be executed through keyboard shortcuts Snood Linux - Desktop 0 04-22-2009 09:30 AM
Squid Proxy is unable to log "access.log" file. nishith Linux - Server 6 08-10-2008 12:00 AM
New SQUID user: How to clear the "access.log" and "store.log" automatically? yuzuohong Linux - Networking 2 12-02-2006 05:37 AM
xstart: Cannot move old "/var/log/XFree86.0.log.old" linuxgamer09483 Linux - Newbie 2 02-18-2004 07:52 PM

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

All times are GMT -5. The time now is 05:04 AM.

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