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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T07:21:49+00:00 2026-05-21T07:21:49+00:00

I have written a bash script that gets three paths based on input parameters

  • 0

I have written a bash script that gets three paths based on input parameters and then then gets the imagename/filename in the path.

Something like:
I provide:

AA=/home/user

Then it uses the find command to get
/home/user/dir2/images/dir/tellmeimage1fun.bin

Finally I have to get tellmeimage1fun.bin as output.

Script:

#!/bin/bash  

echo "arg0 n/k/d"  

AA=$1  
CC=$3  

PATH1="`find $AA/dir2/images/dir/ -name *image1*.bin`"  
PATH2="`find $AA/dir2/images/dir/ -name *bimage2*.bin`"  
PATH3="`find $AA/dir2/images/dir/ -name *cimage3*.bin`"  

if [ $CC = "n" ] ; then  
    PATH=$PATH1  
elif [ $CC = "k" ] ; then  
    PATH=$PATH2  
else  
    PATH=$PATH3  
fi  

#Getting filename name from path:  
IMG="`ls $PATH | cut -d "/" -f6`"

OUTPUT:  
/users/prasapat/bin/sl5: line 22: ls: command not found  
/users/prasapat/bin/sl5: line 22: cut: command not found  

If I give complete paths to ls and cut they work. But i don’t want to do that for all commands in the script. If i remove the last line and echo the PATH variable it is completely fine. Only after adding the last command, I see the problem.

What am I doing wrongly?

  • 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-05-21T07:21:50+00:00Added an answer on May 21, 2026 at 7:21 am

    The problem is that you are redefining the PATH variable where bash looks into to find the binary files if you don’t use a complete path when calling.

    You should change the PATH in your bash script to MYPATH or something like that, so that it doesn’t mess with the already environmental variables.

    If you don’t know what the PATH variable is for you can look at wikipedia’s article

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

Sidebar

Related Questions

I have a bash script that runs a simulation program written in Fortran 90,
I have a bash script that performs makes and then aborts when a make
I have written a little bash script that reads commands (one per line), in
I have written a script that gets data from solr for which date is
I have written a bash script, A, that is calling another script, B, over
I have written a very simple bash script to help me migrate from dev
I have the following snippet in a bash script written in Solaris 10: printf
I have written a small bash script which needs an ssh tunnel to draw
I have this bash script on the server that runs every hour, via cron.
I have written (tried to) this small bash script for searching through a range

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.