Skip to main content

Questions tagged [case]

A reserved word in shells used for running commands based on pattern matching. It must be terminated by "esac".

2 votes
2 answers
398 views

I want to know if there is another alternative in Bash to execute multiple blocks when the pattern matches. I don’t want to use another command, if statements, or two or more separate case blocks or ...
ReflectYourCharacter's user avatar
-1 votes
1 answer
153 views

I want something like this: time="1m" case "$time" in *h*) *m*) *s*) echo "handling several cases for h, m, s tokens" ;; *) echo "...
Anton Samokat's user avatar
2 votes
1 answer
339 views

case "$1","$name" in -py | --python | --python3,*) if [[ "$name" =~ \..+$ ]]; then That doesn't catch stuff, which actually it should, like… USERNAME@HOSTNAME:~$ ...
futurewave's user avatar
2 votes
2 answers
656 views

I have a for loop and case statements. The for loop has quite a bit element list and the case statement will assign an 1D array or a vector. These values will be used in for loop after. I have the ...
BircanA's user avatar
  • 21
0 votes
0 answers
30 views

I am attempting to write a bash script that takes input from the keyboard and displays text depending on what number was entered: #!/bin/bash read -p "Enter your age: " AGE case $AGE in ...
Randy Haley's user avatar
-2 votes
1 answer
444 views

I just realized that in shell scripting esac, the closing statement for case is just case reversed. This may be a stupid question but does esac actually mean something (ie an abbreviation) or was it ...
Kaiden Prince's user avatar
0 votes
1 answer
380 views

I have two arrays and want to print a value from ARRAY2 depending on the applicable value in ARRAY1. #!/usr/bin/env bash ARRAY1=(bb.service.sql bw.service.sql) ARRAY2=(bb bw) case $ARRAY1[@] in ${...
vrms's user avatar
  • 287
1 vote
1 answer
128 views

I'm making a script for Docker environments, and I'm a bit stuck with a pigeonhole I've gotten myself into. #!/bin/bash set -euo pipefail # Variables gituser="modem7" gitrepo="docker-...
Modem7's user avatar
  • 11
1 vote
1 answer
80 views

I have made a simple backup program for my bin folder. It works. Code and resultant STDOUT below. Using rsync to copy from local ~/bin folder to a /media/username/code/bin folder. The code works fine ...
Dee's user avatar
  • 33
0 votes
1 answer
617 views

I encountered such a problem when passing a parameter to a script, the function corresponding to the case menu is not executed. The script accepts parameters as input and performs the appropriate ...
Maverick's user avatar
0 votes
1 answer
44 views

I wish to search for a string mongo and not starting with comment i.e # in a file. homedir=`ls -d ~` echo "$homedir" if [[ `cat $homedir/2_need_softwares.txt | grep -v '^#' | grep -iq ...
Ashar's user avatar
  • 527
2 votes
3 answers
3k views

I am writing a script which must accept a word from a limited predefined list as an argument. I also would like it to have completion. I'm storing list in a variable to avoid duplication between ...
vatosarmat's user avatar
2 votes
1 answer
2k views

I'm trying to write a case statement where the variable argument does not match a test expression. In other words: case $db in [Some Code Here]) echo "Not a valid database type&...
Aditya K's user avatar
  • 2,270
5 votes
3 answers
1k views

I want to know if there is any way to case on multiple variables at once, like this: #/bin/bash arr1=(1 2) arr2=(3 4) foo=1 bar=2 case $foo && $bar in ${arr1[@]}) echo "...
GamerAwesome949's user avatar
0 votes
1 answer
762 views

I have a bash script where I want to set a case variable. For file1 there are two different NUMBER variables that I then I want to pass to a text file. I have tried the following: case $FILE in &...
Maria's user avatar
  • 1

15 30 50 per page
1
2 3 4 5
7