LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-02-2011, 12:17 AM   #1
gloridel
LQ Newbie
 
Registered: Apr 2007
Posts: 25

Rep: Reputation: 0
Question Clear: Command not found


I am trying to learn shell scripting and the first attempt is an error

I found this tutorial :http://www.freeos.com/guides/lsst/ch02sec01.html

and made the sample program.

basically the script just contains clear
Code:
clear
but I got the error
the clear command is located at my /usr/bin
which is already set in my PATH

I am running bash shell.
 
Old 09-02-2011, 12:44 AM   #2
{BBI}Nexus{BBI}
Senior Member
 
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 6, KDE Neon
Posts: 4,313

Rep: Reputation: 212Reputation: 212Reputation: 212
Are you sure you have /usr/bin in your path? You can check with
Code:
echo $PATH
If /usr/bin is not listed you need to add it to your /home/username/.bash_profile file.
 
Old 09-02-2011, 12:46 AM   #3
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,465

Rep: Reputation: Disabled
Did you make your script executable?
jdk

Last edited by jdkaye; 09-02-2011 at 12:49 AM.
 
Old 09-02-2011, 01:43 AM   #4
gloridel
LQ Newbie
 
Registered: Apr 2007
Posts: 25

Original Poster
Rep: Reputation: 0
yes it is in my path::

$echo $PATH
/usr/local/bin:/bin:/usr/bin


yes it is executable:
-rwxrwxrwx testsh.sh
 
Old 09-02-2011, 01:52 AM   #5
{BBI}Nexus{BBI}
Senior Member
 
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 6, KDE Neon
Posts: 4,313

Rep: Reputation: 212Reputation: 212Reputation: 212
What happens if you simply type clear yourself? BTW what distro are you using?
 
Old 09-02-2011, 01:53 AM   #6
hi2arun
Member
 
Registered: Apr 2010
Distribution: Fedora
Posts: 109
Blog Entries: 4

Rep: Reputation: 34
1. Output of
Quote:
whereis clear
or
Quote:
which clear
2. Do you see an error when 'clear' is executed?
Quote:
clear
3. Output of
Quote:
sh -x <name of your script>
 
Old 09-02-2011, 02:03 AM   #7
gloridel
LQ Newbie
 
Registered: Apr 2007
Posts: 25

Original Poster
Rep: Reputation: 0
if i simply type clear, it clears the screen

$which clear
/usr/bin/clear

distro; Redhat

I tried doing this:

code=clear

the error was gone, but it did not execute the clear command.
 
Old 09-02-2011, 02:09 AM   #8
hi2arun
Member
 
Registered: Apr 2010
Distribution: Fedora
Posts: 109
Blog Entries: 4

Rep: Reputation: 34
Quote:
Originally Posted by gloridel View Post
if i simply type clear, it clears the screen

$which clear
/usr/bin/clear

distro; Redhat

I tried doing this:

code=clear

the error was gone, but it did not execute the clear command.
Can you paste the script here?

Are you assigning 'clear' to 'code' and calling 'code'?
 
Old 09-02-2011, 02:20 AM   #9
gloridel
LQ Newbie
 
Registered: Apr 2007
Posts: 25

Original Poster
Rep: Reputation: 0
Code:
code=clear
this is the only thing inside my testsh.sh file
i execute the script by "./testsh.sh" only

sorry , this is really my first time making my own shell script
 
Old 09-02-2011, 02:22 AM   #10
hi2arun
Member
 
Registered: Apr 2010
Distribution: Fedora
Posts: 109
Blog Entries: 4

Rep: Reputation: 34
No problem. Shell scripting is cool as you learn it.

well. After the line
Quote:
code=clear
, you have to call it as follows

Quote:
$code
Or, you can directly call 'clear' in the code.

Quote:
#!/bin/sh
clear
 
1 members found this post helpful.
Old 09-02-2011, 02:31 AM   #11
{BBI}Nexus{BBI}
Senior Member
 
Registered: Jan 2005
Location: Nottingham, UK
Distribution: Mageia 6, KDE Neon
Posts: 4,313

Rep: Reputation: 212Reputation: 212Reputation: 212
Quote:
Originally Posted by gloridel View Post
Code:
code=clear
That is not even in the tutorial you said you followed.
 
Old 09-02-2011, 02:32 AM   #12
gloridel
LQ Newbie
 
Registered: Apr 2007
Posts: 25

Original Poster
Rep: Reputation: 0
i forgot to put this line

Code:
#!/bin/bash
and there where some extra characters so i got the following errors

-bash: ./testsh.sh: /bin/bash^ bad interpreter

so I used vi this time and wrote the function again and its working like magic

thank you so much
 
Old 09-02-2011, 02:34 AM   #13
gloridel
LQ Newbie
 
Registered: Apr 2007
Posts: 25

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by {BBI}Nexus{BBI} View Post
That is not even in the tutorial you said you followed.
sorry about that,

the original code was

Code:
clear
echo "Hello $USER"
echo "Today is \c"; date
echo "Number of user login : \c"; who | wc -1
cal
exit 0
but I got some errors command not found, so I was experimenting with it and posted the latest code I had ..
 
Old 09-02-2011, 02:34 AM   #14
hi2arun
Member
 
Registered: Apr 2010
Distribution: Fedora
Posts: 109
Blog Entries: 4

Rep: Reputation: 34
Well... if you ever encountered such error due to extra characters... this happens if you used editors on Windows...

you can resolve it by converting the script to unix format...

Quote:
dos2unix <name_of_ur_script>
 
Old 09-02-2011, 02:41 AM   #15
gloridel
LQ Newbie
 
Registered: Apr 2007
Posts: 25

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by hi2arun View Post
Well... if you ever encountered such error due to extra characters... this happens if you used editors on Windows...

you can resolve it by converting the script to unix format...
thanks.
 
  


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
clear command sud Linux - Newbie 1 04-23-2009 01:54 AM
how do i replace the clear "clear screen" with the cls command thefedexguy SUSE / openSUSE 2 12-02-2005 05:02 PM
history clear command suguname Linux - Newbie 5 03-05-2005 09:32 AM
Command to clear RAM? flamesrock Linux - Software 9 11-22-2004 06:41 PM
Always clear last command GUIPenguin Linux - General 3 09-14-2004 04:45 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:47 PM.

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