LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 04-17-2011, 08:25 PM   #1
MetaMan
Member
 
Registered: Apr 2011
Distribution: Arch Linux :D
Posts: 50

Rep: Reputation: 0
Post Issue in a shell script using an if statement and "wall"


OK, I made a simple script called "msg" to make it simpler to use the "wall" command, but it is giving me some issues. The problem is more cosmetic than performance, but it's annoying.

OS: Ubuntu 10.10
Text Editor: Nano (Probably not important, but hey...)

Here's what I got:
Code:
#!/bin/bash

# Changes color to yellow
tput setaf 3
echo "Type your message and press Enter:"
#Resumes normal color
tput sgr0
read message

#Checks is message is blank
if ["$message" -eq ] ; then

#Sets color to red
tput setaf 1
echo "ERROR: You didn't type anything to broadcast!"
#Resumes normal color
tput sgr0

else

#Changes color to green
tput setaf 2
echo "$message" | wall
#Resumes normal color
tput sgr0
fi
For the most part it does what it's supposed too, but when it's used, I get this:

Code:
jesse@UbuntAWESOME-2:/usr/sbin$ msg
Type your message and press Enter:
This is a test
/usr/sbin/msg: line 11: [This is a test: command not found
                                                                               
Broadcast Message from jesse@UbuntAWESOME-2                                    
        (/dev/pts/0) at 20:17 ...                                              
                                                                               
This is a test 
It works, but adds in that "/usr/sbin/msg: line 11: [This is a test: command not found." Any idea what is wrong? Obviously it's something with line 11 but I've tried everything I can think of.
 
Old 04-17-2011, 08:35 PM   #2
AlucardZero
Senior Member
 
Registered: May 2006
Location: USA
Distribution: Debian
Posts: 4,824

Rep: Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615Reputation: 615
Code:
["$message"
Missing space after the [. [ is a command, not syntactic sugar. Like all other commands, there needs to be a space after it.
Code:
[ "$message"
 
Old 04-17-2011, 08:50 PM   #3
MetaMan
Member
 
Registered: Apr 2011
Distribution: Arch Linux :D
Posts: 50

Original Poster
Rep: Reputation: 0
Another Problem

I added a space, but now I'm getting this:
Code:
jesse@UbuntAWESOME-2:/usr/sbin$ msg
Type your message and press Enter:
This is a test
/usr/sbin/msg: line 11: [: This is a test: unary operator expected
                                                                               
Broadcast Message from jesse@UbuntAWESOME-2                                    
        (/dev/pts/0) at 20:47 ...                                              
                                                                               
This is a test
 
Old 04-17-2011, 09:07 PM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,359

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
Code:
if [[ "$message" = "" ]] ; then
http://tldp.org/LDP/abs/html/testcon...ml#DBLBRACKETS See the notes on using double brackets and the general rule that such operators etc such as [[, -eq, , =, ]] etc must be surrounded by at least one space on each side for the parser to work correctly.
See here for numeric vs string comparison operators. http://tldp.org/LDP/abs/html/compari...l#ICOMPARISON1
 
Old 04-17-2011, 09:58 PM   #5
MetaMan
Member
 
Registered: Apr 2011
Distribution: Arch Linux :D
Posts: 50

Original Poster
Rep: Reputation: 0
Thanks! Fixed!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Errors executing shell script: "command not found" and "no such file or directory" eko000 Linux - Newbie 1 01-14-2011 07:54 AM
[SOLVED] Shell scripting, difference of "source script.sh" and "./script.sh" Squall90 Programming 4 07-31-2010 04:40 PM
Shell script: I have string "abc____def____ghi", how to make "abc def ghi" vouser Programming 8 03-09-2010 10:01 PM
converting shell script from "dialog" to "xdialog" kushalkoolwal Programming 1 02-25-2008 08:40 PM
Shell Script: Find "Word" Run "Command" granatica Linux - Software 5 07-25-2007 07:42 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 06:44 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration