Skip to main content
deleted 12 characters in body
Source Link
ctrl-alt-delor
  • 28.8k
  • 11
  • 66
  • 113

I want to create a bash script which will have lot of options while executing.

# script.sh  --dry-run --user <parameter1> --pass <parameter2>

I heard about getopt option but looks like we can only write either --user or --password or --dry-run and not all of them. Basically I want to take --user parameter1 as input1 and --pass parameter2 as input2 and a special case where if --dry-run option is there, then execute only dry-run code instead of production.

#!/bin/bash
user=$1
pass=$2

help() {
    cat<<EOF
    Usage : $0 --dry-run --user <user_id> --pass <password>
    you can specify --dry-run or --production
    EOF
}

[ ${3} ] || help
 
function dry_run() {
    // --dry-run code 
}

function production() {
   // --production code 
}

I want to validate --dry-run and if the option is --dry-run, then execute function dry_run() else execute production() function. But how to write options and validations ?

I want to create a bash script which will have lot of options while executing.

# script.sh  --dry-run --user <parameter1> --pass <parameter2>

I heard about getopt option but looks like we can only write either --user or --password or --dry-run and not all of them. Basically I want to take --user parameter1 as input1 and --pass parameter2 as input2 and a special case where if --dry-run option is there, then execute only dry-run code instead of production.

#!/bin/bash
user=$1
pass=$2

help() {
    cat<<EOF
    Usage : $0 --dry-run --user <user_id> --pass <password>
    you can specify --dry-run or --production
    EOF
}

[ ${3} ] || help
 
function dry_run() {
    // --dry-run code 
}

function production() {
   // --production code 
}

I want to validate --dry-run and if the option is --dry-run, then execute function dry_run() else execute production() function. But how to write options and validations ?

I want to create a bash script which will have lot of options while executing.

# script.sh  --dry-run --user <parameter1> --pass <parameter2>

I heard about getopt option but looks like we can only write either --user or --password or --dry-run and not all of them. Basically I want to take --user parameter1 as input1 and --pass parameter2 as input2 and a special case where if --dry-run option is there, then execute only dry-run code instead of production.

#!/bin/bash
user=$1
pass=$2

help() {
    cat<<EOF
Usage : $0 --dry-run --user <user_id> --pass <password>
you can specify --dry-run or --production
EOF
}

[ ${3} ] || help
 
function dry_run() {
    // --dry-run code 
}

function production() {
   // --production code 
}

I want to validate --dry-run and if the option is --dry-run, then execute function dry_run() else execute production() function. But how to write options and validations ?

added 44 characters in body
Source Link
ctrl-alt-delor
  • 28.8k
  • 11
  • 66
  • 113

I want to create a bash script which will have lot of options while executing.

# script.sh  --dry-run --user <parameter1> --pass <parameter2>

I heard about getopt option but looks like we can only write either --user or --password or --dry-run and not all of them. Basically I want to take --user parameter1 as input1 and --pass parameter2 as input2 and a special case where if --dry-run option is there, then execute only dry-run code instead of production.

#!/bin/bash
user=$1
pass=$2

help() {
    cat<<EOF
    Usage : $0 --dry-run --user <user_id> --pass <password>
    you can specify --dry-run or --production
    EOF
}

[ ${3} ] || help
 
function dry_run() {
    // --dry-run code  
}

function production() {
   // --production code  
}

I want to validate --dry-run and if the option is --dry-run, then execute function dry_run() else execute production() function. But how to write options and validations ?

I want to create a bash script which will have lot of options while executing.

# script.sh  --dry-run --user <parameter1> --pass <parameter2>

I heard about getopt option but looks like we can only write either --user or --password or --dry-run and not all of them. Basically I want to take --user parameter1 as input1 and --pass parameter2 as input2 and a special case where if --dry-run option is there, then execute only dry-run code instead of production.

#!/bin/bash
user=$1
pass=$2

help() {
cat<<EOF
Usage : $0 --dry-run --user <user_id> --pass <password>
you can specify --dry-run or --production
}

[ ${3} ] || help
 
function dry_run() {
// --dry-run code }

function production() {
// --production code }

I want to validate --dry-run and if the option is --dry-run, then execute function dry_run() else execute production() function. But how to write options and validations ?

I want to create a bash script which will have lot of options while executing.

# script.sh  --dry-run --user <parameter1> --pass <parameter2>

I heard about getopt option but looks like we can only write either --user or --password or --dry-run and not all of them. Basically I want to take --user parameter1 as input1 and --pass parameter2 as input2 and a special case where if --dry-run option is there, then execute only dry-run code instead of production.

#!/bin/bash
user=$1
pass=$2

help() {
    cat<<EOF
    Usage : $0 --dry-run --user <user_id> --pass <password>
    you can specify --dry-run or --production
    EOF
}

[ ${3} ] || help
 
function dry_run() {
    // --dry-run code  
}

function production() {
   // --production code  
}

I want to validate --dry-run and if the option is --dry-run, then execute function dry_run() else execute production() function. But how to write options and validations ?

deleted 3 characters in body
Source Link
Anthon
  • 81.4k
  • 42
  • 174
  • 228

I want to create a bash script which will have lot of options while executing.

# script.sh  --dry-run --user <parameter1> --pass <parameter2>

I heard about getopt option but looks like we can only write either --user or --password or --dry-run and not all of them. Basically I want to take --user parameter1 as input1 and --pass parameter2 as input2 and a special case where if --dry-run option is there, then execute only dry-run code instead of production.

#!/bin/bash
user=$1
pass=$2

help() {
cat<<EOF
Usage : $0 --dry-run --user <user_id> --pass <password>
you can specify --dry-run or --production
}

[ ${3} ] || help
 
function dry_run() {
// --dry-run code }

function production() {
// --production code }

I want to validate --dry-run--dry-run and if the option is --dry-run--dry-run, then execute function dry_run()dry_run() else execute production()production() function. But how to write options and validations ? Please help

I want to create a bash script which will have lot of options while executing.

# script.sh  --dry-run --user <parameter1> --pass <parameter2>

I heard about getopt option but looks like we can only write either --user or --password or --dry-run and not all of them. Basically I want to take --user parameter1 as input1 and --pass parameter2 as input2 and a special case where if --dry-run option is there, then execute only dry-run code instead of production.

#!/bin/bash
user=$1
pass=$2

help() {
cat<<EOF
Usage : $0 --dry-run --user <user_id> --pass <password>
you can specify --dry-run or --production
}

[ ${3} ] || help
 
function dry_run() {
// --dry-run code }

function production() {
// --production code }

I want to validate --dry-run and if the option is --dry-run, then execute function dry_run() else execute production() function. But how to write options and validations ? Please help

I want to create a bash script which will have lot of options while executing.

# script.sh  --dry-run --user <parameter1> --pass <parameter2>

I heard about getopt option but looks like we can only write either --user or --password or --dry-run and not all of them. Basically I want to take --user parameter1 as input1 and --pass parameter2 as input2 and a special case where if --dry-run option is there, then execute only dry-run code instead of production.

#!/bin/bash
user=$1
pass=$2

help() {
cat<<EOF
Usage : $0 --dry-run --user <user_id> --pass <password>
you can specify --dry-run or --production
}

[ ${3} ] || help
 
function dry_run() {
// --dry-run code }

function production() {
// --production code }

I want to validate --dry-run and if the option is --dry-run, then execute function dry_run() else execute production() function. But how to write options and validations ?

Source Link
Loading