Jump to content



Photo

confused on unix special character command


  • Please log in to reply
3 replies to this topic

#1 SlayerS_BoxeR

SlayerS_BoxeR

    Neowinian

  • Joined: 10-December 12
  • OS: OS X Mavericks
  • Phone: Iphone 5

Posted 09 March 2013 - 09:01


Write a script that outputs your name. So if your name is "Joe Smith". The script should echo "Joe Smith" to the screen.

the answer is $cat tut2q1.sh

!/bin/bash

This is a script to print Joe Smiths name.

echo 'Joe Smith' $

but after i write $cat blah blah, the next command line gives me > symbol. after finish typing until the end of $, i can't get out of the sh? how do you type those command step by step?

thanks



#2 Haggis

Haggis

    Neowinian Senior

  • Tech Issues Solved: 9
  • Joined: 13-June 07
  • Location: Near Stirling, Scotland
  • OS: Debian 7
  • Phone: Samsung Galaxy S3 LTE (i9305)

Posted 09 March 2013 - 13:06

You have noend explained this very well


Remive the end $

And u need a # at the start of the bin bash line

#3 PeteDaCoder

PeteDaCoder

    Neowinian

  • Joined: 14-March 13

Posted 16 March 2013 - 07:35

For your script to print the name, your bash script should be simply:
#!/bin/bash
echo 'Joe Smith'

However alternatively you can use the command whoami which will return the user's name: i.e.
#!/bin/bash
whoami

#4 Lant

Lant

    Neowinian Senior

  • Joined: 13-April 06

Posted 16 March 2013 - 10:27

Also you should really execute bash scripts by "bash tut2q1.sh", what you are doing is just writing the files contents to the console with cat



Click here to login or here to register to remove this ad, it's free!