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 8727757
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T08:29:52+00:00 2026-06-13T08:29:52+00:00

In this statement I am trying to match if a version ($var2) exist in

  • 0

In this statement I am trying to match if a version ($var2) exist in the path /app/$var1 (application name)

if 
find /app/$var1 -maxdepth 1 -type l -o -type d | grep $var2 #results in a nice list where i can manually get a true match.
# if match is found then execute command.
$realcmd "$@"
    rc=$?
    exit $rc
else
echo "no match, the version you are looking for does not exist"
fi

current code:
this include all my code (not cleaned).
command I run: “./xmodule load firefox/3.6.12”
this version does exit

#!/bin/bash
# hook for some commands

#echo $@  #value of sting that is entered after "xmodule"

cmd=$(basename "$0")
#echo "called as $cmd"

if [[ $cmd = "xmodule" ]]
then
    realcmd='/app/modules/0/bin/modulecmd tcsh'

    # verify parameters
fi
# check if $@ contains value "/" to determine if a specific version is requested.
case "$@" in
*/*)
    echo "has slash"
var1=$(echo "$@" | grep -Eio '\s\w*') # Gets the aplication name and put it into var1
echo $var1   # is not printed should be "firefox"
var2=$(echo "$@" | grep -o '[^/]*$')  # Gets version name and put it into var2 
echo $var2 
# Checking if version number exist in /app/appname/
if find /app/$var1 -noleaf -maxdepth 1 -type l -o -type d | grep $var2; then
    $realcmd "$@"
    exit $?
else
    echo "no match, the version you are looking for does not exist"
    # Should there be an exit here?
fi
    ;;

*)
    echo "doesn't have a slash"
    ;;
esac

output:
mycomputer [9:55am] [user/Desktop/script] -> ./xmodule load firefox/3.6.12
‘has slash

3.6.12
no match, the version you are looking for does not exist

Where there is a blank (above 3.6.1) there should be the application name. I am now realizing that this must be my problem sins the path that it uses i likely just /app.
But I do not think I changed anything in that part of the code.

  • 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-13T08:29:53+00:00Added an answer on June 13, 2026 at 8:29 am

    You can use the entire grep pipeline as the condition of the if statement. Use grep -q to keep it from printing the match it finds (unless you want that printed). I also simplified the exit (there’s no need to store $? in a variable if you’re just going to use it immediately). Here’s the result:

    if find "/app/$var1" -maxdepth 1 -type l -o -type d | grep -q "$var2"; then
        $realcmd "$@"
        exit $?
    else
        echo "no match, the version you are looking for does not exist"
        # Should there be an exit here?
    fi
    

    BTW, since you’re going to exit immediately after $realcmd, you could use exec $realcmd "$@" to replace the shell with $realcmd instead of running $realcmd as a subprocess.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to produce this XML statement (minus the formatting and specific values): <swatchcolor
I am trying to make this IF statement work, but I can't seem to
I have a problem when trying to execute this update statement (below) using C#
I'm using Python 2.5. I'm trying to use this 'with' statement. from __future__ import
I'm trying to remove the eval statement in this function. I'm used to the
I'm trying to figure out how I can do an if statement with this
I'm trying to match the text foo between the two brackets in this following
I'm currently trying to return a match to a Foreach statement which is contained
I'm trying to implement a switch case statement like this: switch (active.attr('class')){ case video:
I'm trying to create a SQL statement to find the matching record based on

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.