I'am doing a tutorial where a simple calculator was given, then i noticed that you can't actually multiply
this is how i have approached the problem so far. i just need if the user enters "*"
to change it to "/*" ,is it possible? i know that * means the name of the last file in the directory or something similar so are they conflicting?
1) is there a there a bigger version from your avatar so that i could use it as a background
2) It works if the given argument is "\*" but i wanted to make sure that even if the user forgets that and simply enters "*" to be able to make the multiply
in this case the result is:
./calculator2.sh 5 * 2
./calculator2.sh: line 13: 52calculator2: value too great for base (error token is "52calculator2")
So is it possible?
3) You've used some command and some syntax that i would like to know more about:
a) typeset -i result (no idea what it does)
b) result=${firstN}${operator}${secondN}
why the curly brackets? and there is no (( )) or `` syntax ,what makes the
difference here?
c) set -f (same as a )
1) is there a there a bigger version from your avatar so that i could use it as a background
That I don't know -- if you 'google' for 'beaches', you may find something. It should not be difficult.
Quote:
2) It works if the given argument is "/*" but i wanted to make sure that even if the user forgets that and simply enters "*" to be able to make the multiply
in this case the result is:
./calculator2.sh 5 * 2
./calculator2.sh: line 13: 52calculator2: value too great for base (error token is "52calculator2")
So is it possible?
When you are in the unix command line and you enter a metacharacter,
the shell will interpret it and look for file names that matches the resulting
regular expression.
If you do not want it to happen, you have two solutions:
1) Escape the metacharacter.
2) 'set -f'
Quote:
3) You've used some command and some syntax that i would like to know more about:
a) typeset -i result (no idea what it does)
'typeset' declares shell variables.
'-i' declares an integer.
Quote:
b) result=${firstN}${operator}${secondN}
why the curly brackets? and there is no (( )) or `` syntax ,what makes the
difference here?
You (we) should always use the curly brackets when using the value of shell variables. Here is one example of why it is necessary:
Quote:
c) set -f (same as a )
Tells the shell to ignore filename metacharacters.
Great post, you are the man!! (literally and metaphorically )
Ok now i understand a little better you used typeset inside the function in order to make the variable global. (no need for return $variable)
and the brackets example couldn't be better.
The set -f doesn't seem to work in my situation.
maybe it's meant for another reason for using it inside the script before a grep command or a find command i am not sure.
But what i actually want is to escape the character "*" after it is inserted by the user.
I cant make it work no matter what, the system cannot ignore the asterisk and behave as if it was just another with no meaning character.
If your variable contains special characters, like "*", then you will need to "double-quote" the variable whenever you use reference it, e.g. at the ksh prompt...
Hi there, Im sure there is a simple explanation for this but I have a file like this with no balnk lines
peter
paul
john
I run the command
# var=`grep paul file.txt`
# echo $var
paul
# echo $var | wc -l
1
but when I grep for a value that isnt in the file, i still... (4 Replies)
Hello;
I need to print two previous lines after searching for a reg exp:
awk '/haywood/'
should produce the following
===================
p9J46THe020804 89922 Tue Oct 18 21:06 MAILER-DAEMON
(host map: lookup (haywood.com): deferred)
... (1 Reply)
Hi, I have a very simple script like below:
for n in 10 20 30
do
for a in 30 40 50 60 70 80
do
for r in 2 3 4 5 6 7
do
m=$((r*a))
count=1
while
do
echo "a = " $a ", m = " $m ", n = " $n
... (2 Replies)
I'm trying to port some code over to unix Solaris. I'm not really a unix programmer so I'm sure this is something straight-forwards but I'm getting the following:
> g++ -c CTrade.cpp
In file included from CTrade.cpp:1:
stdafx.h:6: warning: `#pragma once' is obsolete
CTrade.cpp:4: iostream: No... (1 Reply)
I have my jsp page located at
/install/apache-tomcat-5.5.29/webapps/jsp-examples/light/login.jsp
There fore i will have to use following url to access it.
localhost:8080/jsp-examples/light/login.jsp
How would i make this little shorter like.
localhost:8080/login.jsp
I m using... (13 Replies)
Hi all,
I am looking to create words from a sentence which adhere to a custom search pattern from my website:
Example:
! +! / += ~
where the terms ! = not, +! = AND NOT, += - and equals and ~ = can be like....
Now here is the issue...i want to split a sentence like the one above on... (1 Reply)
Hi there,
I was trying to add a line of text in the middle line of a file.
I have counted the lines in the file, and then I divide it into 2, after that I am stuck on how am I suppose to append the line on that file? When I tried to use this command 'second line >> filename' it appends it at... (3 Replies)
Hi,
I have successfully setup my Samba server on my Sun Solaris 8 Sparc machine. My Win2000 workstation is able to see the unix worstation and its shared directory from Network Neighborhood.
However, the Unix workstation appears as Ip address instead of Hostname on my network neighborhood... (5 Replies)