#! /bin/bash
declare -a dirs
i=1
for d in */
do
dirs[i++]="${d%/}"
done
echo "There are ${#dirs[@]} dirs in the current path"
for((i=1;i<=${#dirs[@]};i++))
do
echo $i "${dirs[i]}"
done
echo "which dir do you want?"
echo -n "> "
read i
echo "you selected ${dirs[$i]}"Sunday, 21 June 2020
How do you store a list of directories into an array in Bash (and then print them out)?
Subscribe to:
Post Comments (Atom)
How to check if a file contains a specific string using Bash
In case if you want to check whether file does not contain a specific string, you can do it as follows. if ! grep -q SomeString "$File...
-
You can use it like this: ## declare an array variable declare - a arr =( "element1" "element2" "element3...
-
What ultimately worked for me was to check whether the shell was an interactive shell. I based the solution on this other post at unix.stack...
-
printf "%s\n" "${!array[@]}" a2 a1 f50 zz b1 printf "%s\n" "${array[@]}" 2 1 abcd Hello Worl...
No comments:
Post a Comment