0

I have a list of 100+ folders in a linux at a folder path "files/data" where I already have basic script "list.sh".

for d in files/data/*
do
echo $d
done

When I run it...

sh list.sh

It is listing all the 100+ folders (amazon, apple, cola, pepsi, and etc...) in side the "files/data" folder. But I am looking for some if command implementation to achieve the bellow.

When I call...

sh list.sh --brand=apple

Then it should only list "apple" and if i call...

sh list.sh --brand=all

Then it should list all the 100+ folders (amazon, apple, cola, pepsi, and etc...).

Thanks.

1 Answer 1

1

I've edit your's script

Usage:

./script.sh all - show all dirs in folder path

./script.sh apple - show apple dirs

You can't use script without parameter because usage of grep.

Hope that's all what you need

#!/bin/bash

brand=$1


function ShowDirs()
{
for d in files/data/*
do
    if ! [[ $brand == all ]];
     then
        echo $d | grep $brand
    else
        echo $d
    fi
done
}

ShowDirs
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.