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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:58:38+00:00 2026-05-30T07:58:38+00:00

This is my code: #!/bin/bash cat input$1 | ./prog$1 > output$1 && if[ $2

  • 0

This is my code:

#!/bin/bash
cat input$1 | ./prog$1 > output$1 && if[ "$2" != "" ]; diff output$1 expected$1;

This then happens:

$ ./run.sh
./run.sh: line 2: if[ no !=  ]: command not found
$

I thought that I could run if statements on one line? is that what the problem is?

  • 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-30T07:58:40+00:00Added an answer on May 30, 2026 at 7:58 am

    it turns out that there needs to be a space between the if and the [. Also, I put in the then and fi keywords.

    The following worked.

    #!/bin/bash
    cat input$1 | ./prog$1 > output$1 && if [ "$2" != "" ]; then diff output$1 expected$1; fi
    

    EDIT:

    as commented below (and in another answer), this can elegantly be shortened to:

    cat input$1 | ./prog$1 > output$1 && [ "$2" != "" ] && diff output$1 expected$1
    

    in which case I don’t even have to remember any of the rules about how to use the if construct 🙂

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

Sidebar

Related Questions

I have a code snippet, as follows. #!/bin/bash filename=tmp_list_filenames line_index=0 cat $filename | while
This is my code for a bubble sort on n numbers: #!/bin/bash echo -n
I'm using this script for building application from command line: #!/bin/bash TARGET=signtest CONFIGURATION=Debug SDK=iphoneos
Consider the following code snippet: #!/bin/bash #This program tests the if statement in bash.
Can i get this value in this variable [Linux Bash] my code #!/bin/bash COUNTER=1
Here's my code to display some dialogs. #!/bin/bash output=$(zenity --list --text=Choose action --column= --hide-header
This code triggers the complaint below: #!/usr/bin/perl use strict; use warnings; my $s =
I've this code in my build.xml: <exec executable=cmd osfamily=winnt> <arg value=/c/> <arg value=xsltproc\bin\xsltproc.exe/> <arg
Im trying to run this code . Basically I want the https://admin:qwerty123@ '$dmp':7777/set_param?'$params command
Consider foo.sh: #!/bin/bash function foo() { source another.sh echo This shouldn't be executed. Return

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.