Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8689655
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T23:42:18+00:00 2026-06-12T23:42:18+00:00

linux 3.5.6-1.fc17.x86_64 GNU bash, version 4.2.37 Hello, I have the following bash script file.

  • 0
linux 3.5.6-1.fc17.x86_64
GNU bash, version 4.2.37

Hello,

I have the following bash script file. That I am using to test my program. However, I want to be able to test with and without valgrind. So I get the argument from the command line ‘valgrind’ and compare in the if statement. However, my test cases will get bigger over time, and I will have to repeat a lot of code in the if-else. Is there a way to minimize this if-else?

Many thanks for any suggestions,

#!/bin/bash

# Abort on error
set -e

echo $1

if [ "$1" == "valgrind" ]; then
    echo "TEST STARTED RUNNING WITH VALGRIND"
    echo "TEST CREATE DATABASE"
    valgrind ./db db.dat c
    echo "TEST CREATE DATABASE OK"

    echo "TEST INSERT"
    valgrind ./db db.dat s 1 steve steve@mail.com
    valgrind ./db db.dat s 2 ben ben@live.com
    valgrind ./db db.dat s 3 lisa lisalow@mailcity.com
    echo "TEST INSERT OK"

    echo "TEST LIST"
    valgrind ./db db.dat l
    echo "TEST LIST OK"

    echo "TEST DELETE"
    valgrind ./db db.dat d 2
    echo "TEST DELETE OK"

    echo "TEST LIST"
    valgrind ./db db.dat l
    echo "TEST LIST OK"

    echo "TEST FETCH"
    valgrind ./db db.dat g 2
    valgrind ./db db.dat g 3
    echo "TEST FETCH OK"

    echo "TEST COMPLETED OK"
else
    echo "TEST STARTED"
    echo "TEST CREATE DATABASE"
    ./db db.dat c
    echo "TEST CREATE DATABASE OK"

    echo "TEST INSERT"
    ./db db.dat s 1 steve steve@mail.com
    ./db db.dat s 2 ben ben@live.com
    ./db db.dat s 3 lisa lisalow@mailcity.com
    echo "TEST INSERT OK"

    echo "TEST LIST"
    ./db db.dat l
    echo "TEST LIST OK"

    echo "TEST DELETE"
    ./db db.dat d 2
    echo "TEST DELETE OK"

    echo "TEST LIST"
    ./db db.dat l
    echo "TEST LIST OK"

    echo "TEST FETCH"
    ./db db.dat g 2
    ./db db.dat g 3
    echo "TEST FETCH OK"

    echo "TEST COMPLETED OK"
fi
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T23:42:19+00:00Added an answer on June 12, 2026 at 11:42 pm

    I would do it like this

    VALGRIND=""
    if [ "$1" == "valgrind" ]
    then
      VALGRIND="valgrind"
    fi
    
    echo "TEST STARTED"
    echo "TEST CREATE DATABASE"
    $VALGRIND ./db db.dat c
    echo "TEST CREATE DATABASE OK"
    ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

git version 1.7.11.4 3.5.3-1.fc17.x86_64 #1 SMP x86_64 x86_64 x86_64 GNU/Linux Hello, When I try
In Linux, say I have the following file (e.g. conf.properties): HOST_URL=http://$HOSTNAME STD_CONFIG=http://$HOSTNAME/config USER_CONFIG=http://$HOSTNAME/config/$unconfigured I
Linux bash script: function Print() { echo $1 } Print OK This script runs
Linux bash script: #!/bin/bash function Print() { echo $1 } var=* Print $var Execution
Using Linux environment with java,I'm having the config file which should be configured before
Linux gcc 4.4.1 I have this function that passes this second parameter that casts
linux gcc 4.4.1 I have the following fprintf statement and I would like to
In linux. I want to build an autoclicker that will have an enable/disable function
(Linux newbie here) I have a directory containing a master file 'cs010101.SETUP' and a
using linux commands in my c++ program. Trying to download a url from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.