Jump to content


Photo

Using a variable in a command


  • Please log in to reply
5 replies to this topic

#1 ukscotth

ukscotth

    Advanced Member

  • Members
  • PipPipPip
  • 194 posts

Posted 27 February 2014 - 02:11 PM

#!/bin/bash
clear
echo "Enter username :"
read username
cd /
cd /home/$username/

Hi,

 

I'm new to batch scripting and i'm trying to insert a variable into a command but cant get it working, can someone please tell me how I do the following properly :

 

Thanks in advance.

 

 



#2 Zane

Zane

    Advanced Member

  • Administrators
  • 3,865 posts
  • LocationMurphy, NC

Posted 27 February 2014 - 02:29 PM

Do the following? ... what is following what?


btn_donate_SM.gif Want to thank me? Contribute to my PayPal piggy-bank

401299.png

#3 ukscotth

ukscotth

    Advanced Member

  • Members
  • PipPipPip
  • 194 posts

Posted 27 February 2014 - 04:09 PM

Sorry I meant how would I do the code I attached correctly



#4 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,448 posts
  • LocationMississauga, Canada

Posted 28 February 2014 - 05:47 AM

What do you want to achieve? To change the current prompt based on the last directory command when all commands of the script are finished or just to list all sub-directories and files during the process?



#5 ukscotth

ukscotth

    Advanced Member

  • Members
  • PipPipPip
  • 194 posts

Posted 28 February 2014 - 06:41 AM

The above code was just an example. Im simply trying to learn how to use variables in commands. In php I would use quotes and dots such as echo 'hello'.$world

 

Is there a similar way in batch scripting ?



#6 jazzman1

jazzman1

    Advanced Member

  • Gurus
  • 2,448 posts
  • LocationMississauga, Canada

Posted 28 February 2014 - 07:21 AM

The name of the language is "BASH" no "BATCH". So, learn the basics first before to practise. I'm using this resource.






0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

Cheap Linux VPS from $5
SSD Storage, 30 day Guarantee
1 TB of BW, 100% Network Uptime

AlphaBit.com