ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
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.
Hello all. I am supposed to write a simple script in bash for class, and have been having a heck of a time with something that should *probably* be pretty simple, here is what I need (or want, anyway)...
I am writing a script that does arithmetic via the commandline, for instance "./arithmetic 3 * 2" should output "3 * 2 = 6". So here is what I have written:
echo $1 $2 $3 = $(( $1$2$3 ))
Which works fine for everything except multiplication, since the asterisk gets interpreted as a wildcard. So, is it possible to make the script interpret it as the multiplication operator without entering an escape character into the command? Should I be using let instead?
Here are some rules for the writing of the script as given from my instructor:
"Your script should NOT use any conditional or repetition type statements.
Learn how to quote in the shell and it'll serve you for life. You can escape single characters with the \ (backslash) character and quote strings with single and double quotes. man sh (it's long!) describes it all, and it'll be well worth learning. Play around with
Code:
echo $HOME
echo \$HOME
echo "$HOME"
echo '$HOME'
echo hello world
echo hello world
echo "hello world" again
posting homework questions goes against the rules of using LQ.org. it is up to you to understand the work, not us.
Whilst all members responses here have been provided in an encouraging angle rather than a solution as such, members should remember not to provide stock answers in situations like these, as it doens't benefit anyone.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.