Re: OT: bash help

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

 



08/16/2014 04:14 PM, Mark C. Allman wrote:
On Sun, 2014-08-17 at 00:42 +0200, Suvayu Ali wrote:
On Sat, Aug 16, 2014 at 02:44:14PM -0700, Mike Wright wrote:
Hi all,

I'm trying to write a simple script that if provided an argument, uses that,
or if nothing is provided, uses a predefined string.

if [ -n $# ]

This will always be true.  -n tests if a string is empty or not.  0
counts as non-empty.  You should use one of the comparison operators.
Try something like this:

   [ $# -gt 0 ]

Hope this helps,

--
Suvayu

Open source is the future. It sets us free.

Are you looking for behavior that the following test script
demonstrates?

     #!/bin/bash

     theArg=${1:-The Default Value}

     echo $theArg

Thanx Mark,

Very elegant.  I like it.

I was just going through the section on "variable substitution" in "Unix in a Nutshell" and saw that.

--
users mailing list
users@xxxxxxxxxxxxxxxxxxxxxxx
To unsubscribe or change subscription options:
https://admin.fedoraproject.org/mailman/listinfo/users
Fedora Code of Conduct: http://fedoraproject.org/code-of-conduct
Guidelines: http://fedoraproject.org/wiki/Mailing_list_guidelines
Have a question? Ask away: http://ask.fedoraproject.org




[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