Sponsored Content
Full Discussion: Selection from array
Top Forums Shell Programming and Scripting Selection from array Post 303024329 by bignellrp on Saturday 6th of October 2018 05:43:58 AM
Old 10-06-2018
I can't get your script to work.

./test2
./test2: line 2: unexpected EOF while looking for matching `''
./test2: line 7: syntax error: unexpected end of file

Code:
#!/bin/bash
awless -l list routetables --columns ID,NAME,VPC  -filter VPC=vpc-00xxxxxxxxxxe52 | sed -r 's/( *)\| */\1/g; s/  / /g; s/[^ ]* *$//; > TMP
<TMP readarray -ts2 TARR
select OPT in "${TARR[@]}"
  do    echo "$REPLY: $REPLY, variable: $OPT, reduced var: ${OPT% * *}"
  done

------ Post updated at 09:43 AM ------

Just in case it helps here is my bad attempt that doesn't work. I thought posting my bad attempt might confuse the situation as I'm trying to find a simpler solution thats easier to replicate for other searches.

Code:
#!/bin/bash
q=1
for z in `awless -l list routetables --columns ID,NAME,VPC --filter VPC=vpc-00xxxxxxxxxxxe52  |\
 awk '
 /\| vpc/ && NF == 4 { print $2 ":No_Label" }
 /\| vpc/ && NF == 5 { print $2 ":" $4 }
 '`
 do
 array3[$q]=`echo $z | awk -F: ' { print $2 } '`
 array4[$q]=`echo $z | awk -F: ' { print $1 } '`
 echo "   $q. $z" ; q=$(($q + 1))
 done
 read selection2

 if [[ $selection2 =~ ^[0-9][0-9]*$ ]] ; then
  echo
 else
  echo "That selection was not valid"
  exit
 fi

 if [ ${array3[$selection2]} ] ; then
  arrayvar3="${array3[$selection2]}"
  arrayvar4="${array4[$selection2]}"
  echo "Thank you for your selection. I will use this for my script... $arrayvar3 $arrayvar4"
  echo ""
  echo "Processing....."
 else
  echo "That selection was not valid"
  exit
 fi

 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Array and Selection

I have a question: Y X Tabel a is a array multidimensional --> a(1024,20) I load in to array a Text from 6000 row where: in a(1,1) is present the row 1 of original text, in a(1024,1) is present then row 1024 of original test and in... (4 Replies)
Discussion started by: ZINGARO
4 Replies

2. UNIX for Advanced & Expert Users

tray selection

Hello All, Could anyone help me how to selecting the trays in unix . Thanks, Amit kul (3 Replies)
Discussion started by: amit kul
3 Replies

3. Post Here to Contact Site Administrators and Moderators

Opt out selection

Maybe I'm missing something but when I go to CP->Options, I see the box for selecting which forum to opt out of but no way to set it. (5 Replies)
Discussion started by: drhowarddrfine
5 Replies

4. Shell Programming and Scripting

Menu help with array selection

Hi there all I got the following I got multiple arrays named for example STAT_AAAA STAT_AAAB STAT_AAAC STAT_AAAD Now what I want I have chosen an option in a menu to select 1 but I dont want to write for all the same thing so I made it a signle one now what I want is to get STAT_ and... (6 Replies)
Discussion started by: draco
6 Replies

5. Shell Programming and Scripting

Data selection

Hi, I have a file containing details of different departments . Infomration of departments is in various tags file is as below I want to create a new file from the above file which should contain only two fields belonging to one department format There are multiple files... (1 Reply)
Discussion started by: test_user
1 Replies

6. Shell Programming and Scripting

Data selection

Hi, Please note that as a programmer I cannot tell the file format or details of my production files so I have re-framed my file and taken a case of departments. Kindly guide as its related to a production requirement of data containing recors of production customer NOT A HOMEWORK :) I have... (10 Replies)
Discussion started by: test_user
10 Replies

7. AIX

Bulk Fixes Selection

Under smit, one has to manually select each fix with F7. there 9000 fixes left to be marked. How Can I manually install/Mark all of these without SMIT. ---------- Post updated at 02:29 PM ---------- Previous update was at 01:15 PM ---------- From the command line instfix -T -d... (4 Replies)
Discussion started by: mrmurdock
4 Replies

8. UNIX for Dummies Questions & Answers

awk for column selection

Hello, I want to extract all values from table except for those that contain the '*' character in the second column. I tried awk '$2!=*' and this threw a syntax error. Do I need to specify an escape character or != is valid only for numerical comparisons? Thanks, Guss (1 Reply)
Discussion started by: Gussifinknottle
1 Replies

9. Shell Programming and Scripting

Date selection

Hi All, i have log file sample data is 2010/10/09|04:00:00.392|15Minute|BW=0|192.168.0.1 2010/10/08|04:00:00.392|15Minute|BW=0|192.168.0.1 2010/10/07|04:00:00.392|15Minute|BW=0|192.168.0.1 2010/10/05|04:00:00.392|15Minute|BW=0|192.168.0.1 2010/10/03|04:00:00.392|15Minute|BW=0|192.168.0.1... (2 Replies)
Discussion started by: posner
2 Replies

10. Shell Programming and Scripting

If Selection statement

ok im kinda stuck i have a bash script with 4 options 1. Create Script 2. Show Script 3 . Delete script 4. Exithow would i use an if statement for this? im not sure what test command i would use. I know it would be like this (below) to display the script if then cat script1or for the... (10 Replies)
Discussion started by: gangsta
10 Replies
RBASH(1)						      General Commands Manual							  RBASH(1)

NAME
rbash - restricted bash, see bash(1) RESTRICTED SHELL
If bash is started with the name rbash, or the -r option is supplied at invocation, the shell becomes restricted. A restricted shell is used to set up an environment more controlled than the standard shell. It behaves identically to bash with the exception that the follow- ing are disallowed or not performed: o changing directories with cd o setting or unsetting the values of SHELL, PATH, ENV, or BASH_ENV o specifying command names containing / o specifying a filename containing a / as an argument to the . builtin command o specifying a filename containing a slash as an argument to the -p option to the hash builtin command o importing function definitions from the shell environment at startup o parsing the value of SHELLOPTS from the shell environment at startup o redirecting output using the >, >|, <>, >&, &>, and >> redirection operators o using the exec builtin command to replace the shell with another command o adding or deleting builtin commands with the -f and -d options to the enable builtin command o using the enable builtin command to enable disabled shell builtins o specifying the -p option to the command builtin command o turning off restricted mode with set +r or set +o restricted. These restrictions are enforced after any startup files are read. When a command that is found to be a shell script is executed, rbash turns off any restrictions in the shell spawned to execute the script. SEE ALSO
bash(1) GNU Bash-4.0 2004 Apr 20 RBASH(1)
All times are GMT -4. The time now is 02:39 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy