help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] Bash - variable identifier with "-"


From: Greg Wooledge
Subject: Re: [Help-bash] Bash - variable identifier with "-"
Date: Wed, 4 Apr 2018 14:22:04 -0400
User-agent: NeoMutt/20170113 (1.7.2)

On Wed, Apr 04, 2018 at 08:09:59PM +0200, Felipe Salvador wrote:
> #!/bin/bash
> set -x
> 
> list="dragon cvlc rhythmbox totem-audio-preview radiotray"

Use an array to store a list of strings, not a string.  Also prefer a
more descriptive name than "list".  What is it a list OF?

>       declare $p="NO"; else

Use an associative array to store a mapping from strings to values.

Also, don't use which(1).


#!/bin/bash
apps=(dragon cvlc rhythmbox totem-audio-preview radiotray)
declare -A found

for app in "address@hidden"; do
    if command -v "$app" >/dev/null; then
        found[$app]=1
    else
        found[$app]=0
    fi
done

And so on.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]