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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
01-03-2008, 07:36 AM
|
#1
|
Member
Registered: Oct 2007
Posts: 53
Rep:
|
shell scripting/ the fc -l command !
i wrote the following program:
# !/bin/bash
#profile program
function histoire {
HISTSIZE=20
echo “HISTSIZE est égale à” $HISTSIZE
echo “le numéro de la commande est” $fc $-l
}
histoire
exit 0
can someone tell me, why am i not getting the same result, as in when i directly write the command fc -l ? and whats hBl ?
knoppix@knoppix:/ramdisk/home/knoppix/tmp$ chmod +x .profile
+ chmod +x .profile
knoppix@knoppix:/ramdisk/home/knoppix/tmp$ ./.profile
+ ./.profile
HISTSIZE est égale à 20
le numéro de la commande est hBl
|
|
|
01-03-2008, 07:44 AM
|
#2
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
where did you read that "$fc $-l" would do what you want? that means nothing.... try "$((fc -l))" instead.
|
|
|
01-03-2008, 07:49 AM
|
#3
|
Member
Registered: Oct 2007
Posts: 53
Original Poster
Rep:
|
well after trying $(fc -l )
the only thing that wouldnt give me errors was $fc$-l !!
i tried $((fc -l)), but that gives me 0, i want the same list that i get when i simply type fc -l on the xterm !
how can i do that? any idea ?
|
|
|
01-03-2008, 07:55 AM
|
#4
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
yeah it does doesn't it? retard alert.... i knew it didn't look right... sorry, it does basic expression evalution...
# echo $(( 10 + 10 ))
20
you do need $(fc -l) or `fc -l` to actually execute fc as a command. i don't think that that's really useful to you though as it'll print it all on one line... i'd just put the fc command on a new line by itself.
doh! 
Last edited by acid_kewpie; 01-03-2008 at 08:18 AM.
|
|
|
01-03-2008, 08:01 AM
|
#5
|
Member
Registered: Oct 2007
Posts: 53
Original Poster
Rep:
|
neither 'fc -l' nor $(fc -l) worked !
i already tried those two,
maybe i should add some argument or sthg? i cant get the answer that i want,
$(fc -l) gives me hBl as an answer !!
and 'fc -l' gives me fc -l as an answer !!
|
|
|
01-03-2008, 08:03 AM
|
#6
|
Member
Registered: Oct 2007
Posts: 53
Original Poster
Rep:
|
actually $fc $-l gives me hBl as an answer
$(fc -l) gives me nth as an answer !!
|
|
|
01-03-2008, 08:18 AM
|
#7
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
no it's `fc -l` not 'fc -l' but as above i don't think you should use that mechanism at all, just run it normally outside of echo.
|
|
|
01-03-2008, 08:38 AM
|
#8
|
Member
Registered: Oct 2007
Posts: 53
Original Poster
Rep:
|
what do you mean by outside of echo ?
i have this program:i changed the fc -l command :
# !/bin/bash
#profile program
function histoire {
HISTSIZE=20
echo “HISTSIZE est égale à” $HISTSIZE
echo “le numéro de la commande est” `fc -l`
}
histoire
exit 0
BUT I GET NOTHG AS AN ANSWER !
|
|
|
01-03-2008, 08:42 AM
|
#9
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
# !/bin/bash
#profile program
function histoire {
HISTSIZE=20
echo “HISTSIZE est égale à” $HISTSIZE
echo “le numéro de la commande est”
fc -l
}
histoire
exit 0
|
|
|
01-03-2008, 08:53 AM
|
#10
|
Member
Registered: Oct 2007
Posts: 53
Original Poster
Rep:
|
this also gives me "nthg" as an answer !
|
|
|
01-03-2008, 08:54 AM
|
#11
|
Moderator
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,417
|
do you atually mean "nothing"...? or literally a text string as you wrote?? if fc -l doesn't give you an output, then you have no recorded history to output...
|
|
|
01-03-2008, 09:08 AM
|
#12
|
Member
Registered: Oct 2007
Posts: 53
Original Poster
Rep:
|
yes i actually mean nthg, just blank space ,
i have a recorded history to output, and i know that because when i type fc -l in my xterm then i get a long list !!
|
|
|
01-03-2008, 06:38 PM
|
#13
|
HCL Maintainer
Registered: Jan 2006
Distribution: (H)LFS, Gentoo
Posts: 2,450
Rep:
|
Quote:
Originally Posted by mayaabboud
can someone tell me, why am i not getting the same result, as in when i directly write the command fc -l ? and whats hBl ?
|
Both of these questions have simple explanations. First, let’s see what fc does (taken from here):
Quote:
Originally Posted by The Open Group Base Specifications Issue 6
The fc utility shall list, or shall edit and re-execute, commands previously entered to an interactive sh.
|
As you can see, fc only works (or should only work) on an interactive shell (i.e., one in which you can interactively type commands).
For example, consider this simple program (which I will save in a text file named program):
Now, watch what happens when I try to execute it as a script:
Code:
$ chmod +x program
$ ./program
$
And watch what happens if I source it into my interactive shell:
Code:
$ source program
1 cd /tmp
2 cat > program
3 chmod +x program
4 ./program
$
As for “ hBl”, this is the result expanding “ $-l” in a script. You see, it shall be parsed as “ ${-}l” where the internal variable $- has the flags currently set (this is a ksh-ism borrowed by bash). In this case, the flags set are for brace expansion and command hashing.
|
|
|
All times are GMT -5. The time now is 08:51 PM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|