LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 12-04-2008, 04:36 AM   #1
bsaheb
LQ Newbie
 
Registered: Dec 2008
Posts: 3

Rep: Reputation: 0
Unhappy usage of history command inside shell script


Hi All,

I need to write a script which requires to display the output for the shell commands.

I am able to retrieve the result for "ls" but the "history" command execution is failed.

Please let me know if there a way to specify the history command inside the shell script and get the output of it.

Sample Script:

#!/bin/bash
ls
history

Rgrds,
saheb
 
Old 12-04-2008, 04:46 AM   #2
hasanatizaz
Member
 
Registered: Nov 2007
Location: Pakistan
Distribution: Redhat and Debian
Posts: 302
Blog Entries: 1

Rep: Reputation: 34
remove #!/bin/bash
it will work.
 
Old 12-04-2008, 05:03 AM   #3
bsaheb
LQ Newbie
 
Registered: Dec 2008
Posts: 3

Original Poster
Rep: Reputation: 0
Not able to execute the history command.

Please find the error message.

[s9:~]cat a.sh
ls
history

[s9:~]sh a.sh
a.sh logs
bin classes
conf jre
lib local.cshrc
local.login local.profile
a.sh: history: not found
[s9:~]
 
Old 12-04-2008, 07:12 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.9, Centos 7.3
Posts: 17,374

Rep: Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383Reputation: 2383
Quote:
Note that within a script, the history mechanism is disabled.
http://www.tldp.org/LDP/abs/html/special-chars.html
 
Old 01-05-2010, 08:55 PM   #5
senthilp
LQ Newbie
 
Registered: Jan 2010
Posts: 2

Rep: Reputation: 0
change the permission

Quote:
Originally Posted by bsaheb View Post
Not able to execute the history command.

Please find the error message.

[s9:~]cat a.sh
ls
history

[s9:~]sh a.sh
a.sh logs
bin classes
conf jre
lib local.cshrc
local.login local.profile
a.sh: history: not found
[s9:~]
hi,

give the permission to the script..

chmod 755 a.sh or chmod 777 a.sh

then execute, you will get the output

regards,
senthil.P
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
execute shell command inside of c code? khucinx Programming 6 10-26-2010 09:30 PM
Problem executing mv command inside shell script pablogosse Linux - General 7 12-16-2009 12:21 PM
perl inside a shell script baidym Linux - Newbie 2 05-05-2008 06:42 PM
LXer: CLI Magic: Using command history in the bash shell LXer Syndicated Linux News 0 07-03-2006 12:54 PM
history command from script sharonenoch Programming 5 03-17-2006 07:48 AM

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

All times are GMT -5. The time now is 09:46 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration