I have an assignment to write a script that reads a number from the user and prints stars say if the number is 3 then it would print

** * **

I understand the idea of how to write it, but i try to make a variable that saves * in it but when i echo $variable it would just show all the folders/files in my current place. how do I just save the '*' as a string without it running the function?

  • Please show a sample of code that illustrates the problem. You can edit your question to include this. Don't forget to format it with the {} button on the editing toolbar. – roaima Nov 9 '15 at 22:55

Though you have to be careful with where you use it; since globbing occurs after variable expansion, if you expand it carelessly it'll do the glob operation at expand-time instead. Use echo "$varname" to print it (note the quotes).

  • Thanks alot I forgot the quotes when I print it that was my issue, kinda new to this thanks! – user142424 Nov 9 '15 at 23:00

Just quote the variable.

$ variable='*'
$ echo $variable
file1 file2 file3
$ echo "$variable"
  • Oh god I forgot I had to put the variable in quotes aswell when I do echo "$variable", thanks man! – user142424 Nov 9 '15 at 22:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.