Bash enumerated types


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Bash enumerated types
# 8  
Old 04-01-2012
Quote:
Originally Posted by kristinu
So one does not use the $ sign for the variables?
Anything that uses bash expressions does not require the $ sign eg:
Code:
let expression
(( expression ))
[[ expression ]]

Anywhere else will eg:
Code:
find . -mtime +$vbLevel
if [ $vbLevel -eq $none ]
case $vbLevel in 
    ($medium) echo yes ;;
esac

# 9  
Old 04-01-2012
Any idea why
Code:
printf "-- Name --"

gives invalid option and how can I make it print without error

---------- Post updated at 07:02 PM ---------- Previous update was at 06:58 PM ----------

Quote:
Originally Posted by Scrutinizer
Indeed. let is an arithmetic evaluation. A synonymous notation would be (ksh/bash):
Code:
(( vbLevel=medium ))

And you can also do this:
Code:
none=0 low=1 medium=2 high=3
vbLevel=2
if (( vbLevel > low )); then
  echo hello
fi

This seems to work. I rather set vbLevel to none, medium, ... and do as below. or is it better using
Code:
(( vbLevel=medium ))

Code:
vbLevel=$medium
if (( vbLevel > low )); then
  echo hello
fi

This works too
Code:
vbLevel=$medium
if [ $vbLevel -gt $low ]; then
  echo hello2
fi

---------- Post updated at 07:10 PM ---------- Previous update was at 07:02 PM ----------

I want to stick with the one below. Would this be ok?
Code:
vbLevel=$medium
if (( vbLevel > low )); then
  echo hello1
fi

---------- Post updated at 07:23 PM ---------- Previous update was at 07:10 PM ----------

I get the user to supply none, low, medium and high from a user option.

Example
Code:
/home/chrisd/srv/sunny/hstmy/bin/bash/raytrac.bash --vblv=high

My code then uses

Code:
vbLevel=$medium
if [ $hasArgument_vbLevel == "true" ]; then
  vbLevel=$value_vbLevel
fi

echo "vbLevel = $vbLevel"

if (( vbLevel > medium )); then
  echo "Hello done"
fi

Thus I replace vbLevel by the user string, which is either none, low, medium or high which then gets associated with the number and then I can do
Code:
if (( vbLevel > medium )); then

---------- Post updated at 07:31 PM ---------- Previous update was at 07:23 PM ----------

I thought to use indirect substitution for this

Code:
vbLevel=${!medium}                    # Indirect substitution
if [ $hasArgument_vbLevel == "true" ]; then
  vbLevel=${!value_vbLevel}        # Indirect substitution
fi

if (( vbLevel > medium )); then
  echo "Hello done"
fi

# 10  
Old 04-02-2012
Quote:
Originally Posted by kristinu
Any idea why
Code:
printf "-- Name --"

gives invalid option and how can I make it print without error
[..]
Try:
Code:
printf "%s" "-- Name --"

Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

C++ Returning enumerated type

I am trying to create a function to return me the verbosity level, so I can call it as follows String s = "normal"; Verbosity log_level; log_level = get_log_level(s); I started a version in the last function but I am having trouble getting it to work. #ifndef __VERBOSE_HH__... (1 Reply)
Discussion started by: kristinu
1 Replies

2. Shell Programming and Scripting

bash: find multiple types[solved]

Hi, I would like to use find to search for multiple types. For example search for symlink and regular file but not directories, sockets etc.... Something like: find . -type l,f -name "stuff" But of course it does not work. Is there any way to avoid an if statement and to do it faster? ... (0 Replies)
Discussion started by: Dedalus
0 Replies

3. Programming

enumeration types in C

If I want to declare an array of structures in C and have the number of items in that array to correspond to the items of an enumeration, is there a way to access the maximum value in the enumeration when declaring the array? For instance: typedef struct { various fields.... } ... (3 Replies)
Discussion started by: cleopard
3 Replies

4. UNIX for Dummies Questions & Answers

mime types

Hi, I am trying to launch an ogg movie from a pdf file which has been produced with pdflatex and \movie {\centerline{\includegraphics {grafiques_xerrades/un_manolo_amb_camera.pdf}}} {hlims_xerrades/XocCumuls.ogg} The switch "externalviewer" makes kpdf launch the default... (5 Replies)
Discussion started by: pau
5 Replies

5. UNIX for Dummies Questions & Answers

Two types of pipes?

What is the difference between: cd /tmp tar -cf - *.txt |gzip > tmp_txt.tar.gz and cd /tmp mknod pipe p gzip < pipe > /tmp/tmp_txt1.tar.gz & tar -cf pipe *.txt Apart from the fact that we have to create the pipe file manually, is there any difference in the performance of the two?... (5 Replies)
Discussion started by: blowtorch
5 Replies

6. Filesystems, Disks and Memory

associated file types

I have a file of type .for extension .In a guui based unix environment like solaris if I double click on that file a specific program designed by me has to run which takes this file as the parameter and exceutes the program. Can anyone help me? (8 Replies)
Discussion started by: nhk_srd
8 Replies

7. UNIX for Dummies Questions & Answers

backup types

can anyone explain me difference between tar and ufsdump commands.............and also i wd like to know the difference between incremental and differential backup......... thx in advance (1 Reply)
Discussion started by: girish_shukla
1 Replies

8. UNIX for Dummies Questions & Answers

So many types of LINUX's!

I installed Redhat into my system. The reason? This was the version my friend was running and he told me about this one, so I downloaded and installed it. Simple enough :D But as I am searching the net, I am coming across many other forms of linux made by other companies. Redhat seems to be... (2 Replies)
Discussion started by: Minnesota Red
2 Replies

9. UNIX for Dummies Questions & Answers

servers types

dear sir , i would like to ask about sun solaries servers generations ? i hear about sparc and ultra . i want to know the versions , and is there other servers types ?? Thank (3 Replies)
Discussion started by: tamemi
3 Replies
Login or Register to Ask a Question