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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:50:56+00:00 2026-05-20T12:50:56+00:00

I have a shell script like this. line=$@ # get the complete first line

  • 0

I have a shell script like this.

line="$@" # get the complete first line which is the complete script path 
name_of_file = ${line%.*}
file_extension = ${line##*.}
if [ $file_extension == "php"]
then
ps aux | grep -v grep | grep -q "$line" || ( nohup php -f "$line" > /var/log/iphorex/$name_of_file.log & ) 
fi
if [ $file_extension == "java"]
then
ps aux | grep -v grep | grep -q "$line" || ( nohup java -f "$name_of_file" > /var/log/iphorex/$name_of_file.log & )
fi

here line variable has values like /var/www/dir/myphp.php or /var/www/dir/myjava.java.

The purpose of shell script is to check if these processes are already running and if not i try to run them.I get the following errors.

name_of_file: command not found
file_extension: command not found
[: missing `]'
[: missing `]' 

Any ideas?

  • 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-20T12:50:57+00:00Added an answer on May 20, 2026 at 12:50 pm

    Firstly, the shell processor treats the line:

    name_of_file = ${line%.*}
    

    as the execution of the command:

    name_of_file
    

    with the parameters:

    = ${line%.*}
    

    you need to write it as:

    name_of_file=${line%.*}
    

    This makes it into a variable=value. You need to repeat this for the file_extension = line as well.

    Secondly, the if:

    if [ $file_extension == "php"]
    

    has exactly the same parsing problem, you must have a space before the trailing ], because otherwise the parser thinks you’re checking if $file_extension is equal to the string: “php]”

    if [ $file_extension == "php" ]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In a shell script lets say i have run a command like this for
I'm creating a Shell Script, and I have a file like this called expressions.txt
A really simple shell script question. I have a file with something like this:
I have a PHP script which executes a shell command: $handle = popen('python last',
I would like to introduce multithreading feature in my shell script. I have a
I have a shell script in which I have to execute two queries (on
I have one shell script opening a perl script. This perl script should be
I have a shell script foo.sh which is a qsub job with content: #!/bin/bash
I have $weMountedBoot set to false like this in the beginning of my script:
I'have a bash script calling a jar file like this: awk -f fileformat.awk list.txt

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.