Issue with Lists


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue with Lists
# 1  
Old 04-10-2014
Issue with Lists

Hey guys, so I wrote this simple script. The first time I typed it all out, I had the issue where whatever choice I entered, it would simply tell me it was a "bad selection" aka the else output.

I redid everything, and now no matter the choice, it does the backup option..

My brain hurts, and I'm sure it's something simple. If anyone can offer some insight it would be wonderful. Thanks!



Code:
DATETIME=”$(date +%d.%m.%Y_%H:%M:%S)”
BKFILE=~/Desktop/bash/backup/backup$DATETIME.tar.gz
BKFOLDER=~/Desktop/bash/code/
BKRESULT=~/Desktop/bash/backup/backup$DATETIME.txt
LIST=”Backup Quit”
select OPT in $LIST; do
if [ $OPT = "Backup" ]; then
tar -zcvf $BKFILE $BKFOLDER > $BKRESULT
clear
echo backup saved to:
echo $BKFILE
echo and the results writed to:
echo $BKRESULT
exit
elif [ $OPT = "Quit" ]; then
clear
echo Backup aborded by user
exit
else
clear
echo bad selection
exit
fi
done

# 2  
Old 04-10-2014
At first I thought perhaps somebody had actually installed something that throws errors due to bad spelling Smilie

Ahh well ... check your equals ... there's more than 1 way to do equality checks ...
# 3  
Old 04-10-2014
haha sorry, I'm doing this based on an exercise online. I copied and pasted the reference instead of my actual code. I corrected the spelling in mine :P

and what do you mean check the equals?

---------- Post updated at 02:19 PM ---------- Previous update was at 02:15 PM ----------

lemme redirect at this:

I wrote my own little script to isolate the problem, and I'm finding the same issue

Code:
#!/bin/bash

LIST="One Two Three"

select OPT in $LIST; do
if [ $OPT="One" ]; then
       echo "You chose one!"
elif [ $OPT="Two" ]; then
       echo "You chose two!"
elif [ $OPT="Three" ]; then
       echo "You chose three!"
fi
exit
done



this is giving me the same issue of echoing "You chose one!" regardless of my choice.
# 4  
Old 04-10-2014
Quote:
Originally Posted by jakelawson44
and what do you mean check the equals?
=
^ check them. How do you use them in korn shell?

[edit]
sorry, just being hesitant on giving you the answer Smilie Being kind of new here, not 100% sure how they spot homework questions here, and I don't want to break any rules Smilie So - you're learning? Great - learn Smilie I'll give you hints ... lol
[/edit]
# 5  
Old 04-10-2014
I suppose I was asking for clarification on what I'm checking for. and I don't know the answer to your question.

Just started playing around with Bash scripting.

---------- Post updated at 02:27 PM ---------- Previous update was at 02:22 PM ----------

oh, well I'm at work right now.. at my 9-5.. had some downtime and I'm trying to learn bash scripting to be more of an asset to my company.. would really appreciate help lol.

Definitely not homework.
# 6  
Old 04-10-2014
Code:
if [ "$OPT" = 'One' ]; then

# 7  
Old 04-10-2014
Quote:
Originally Posted by jakelawson44
I suppose I was asking for clarification on what I'm checking for. and I don't know the answer to your question.

Just started playing around with Bash scripting.
Do you do any java or c programming?
I believe the usage of using = for compares is similar in those languages.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Combining lists

Hello everybody. My operating system is Fedora30, shell - bash I faced combining lists. I will be glad for help regarding strings, arrays and so on. The bottom line is as follows. It is necessary to combine each element from the first list with elements from the second. if the second is longer... (4 Replies)
Discussion started by: nezabudka
4 Replies

2. UNIX for Dummies Questions & Answers

Lists in awk

Hi togehter! I would like to write an awk script which prints the first column divided by the sum of the second column: So if this is my list 1 2 2 1 3 1 4 1 it should print a list like this: 1/5 2/5 3/5 4/5 My idea was to use END like this: (3 Replies)
Discussion started by: bjoern456
3 Replies

3. Shell Programming and Scripting

get the lists

I expert, I may cross post something similar but I dirtyed my quesion somehow to be clear in the thread #cat file1 88dee gcc: Grok for callconvention-hard to enable hard float a2ad2 eglibc: package mtrace separately 61487 python: bump PR of packages after update of distutils.bbclass... (1 Reply)
Discussion started by: yanglei_fage
1 Replies

4. Shell Programming and Scripting

combining two lists

Hi, So I I received two lists for my merchandise and both are similar but differences do occur. I want to combine two lists that have similar names but I dont want the similar name to come up twice because I will end up purchasing two of those items. Heres an example below (file is massive). ... (1 Reply)
Discussion started by: kylle345
1 Replies

5. Shell Programming and Scripting

Using foreach with two lists

Hi everybody, I'm trying to use a foreach command with two lists. The file.txt looks like this: var1: 100 200 300 var2: 3 6 9 I'm trying to use a foreach command to associate the two variables together. My script looks like this: #! /bin/tcsh set a=(`cat file.txt | grep 'var1' | cut -d... (8 Replies)
Discussion started by: SimonWhite
8 Replies

6. Shell Programming and Scripting

Shell Script to Create non-duplicate lists from two lists

File_A contains Strings: a b c d File_B contains Strings: a c z Need to have script written in either sh or ksh. Derive resultant files (File_New_A and File_New_B) from lists File_A and File_B where string elements in File_New_A and File_New_B are listed below. Resultant... (7 Replies)
Discussion started by: mlv_99
7 Replies

7. Shell Programming and Scripting

How to get the files lists

Hi All, Need the help in getting the file list which are generated for the time period. example if i want to get the list of file generated between 11 to 12 clock. i used the find command search the files with -cmin flag with -60. find /home/test/* -cmin -60 -type f -exec ls {} \; ... (2 Replies)
Discussion started by: nmadhuhb
2 Replies

8. AIX

grep using lists?

I have a file that contain a list of files. How can I use grep to search the files in the list for a specific pattern? (2 Replies)
Discussion started by: bbbngowc
2 Replies

9. Shell Programming and Scripting

Question on lists

I'm fairly new to shell scripting and would like to know if what I am seeking to do is possible in shell. I'm trying to make a list of strings. The list will be looped through and each member of the list will be used to pass a parsing option to python. My script looks something like this: ... (3 Replies)
Discussion started by: Nacre
3 Replies
Login or Register to Ask a Question