bash, echo or cat both a system variable and the contents of a text file onto 1 line

Posted on 2004-10-21
Last Modified: 2013-12-16
Using bash to pull data out of a file and mix this data with some variables and then echo the results onto 1 line. I have most of this figured out. The output of the echo should look like this
Where joe and hippo is actually data within 2 different files.
Here is what I am actually getting
click here ----->   <----- click here

#start of script
USER="user.txt"                                  ##This is a file with the user name in it
PASSWORD="password.txt"              ##This is a file with the password in it

echo "click here ----->   $FTP$USER$COLON$PASSWORD$AT$SITE   <----- click here"
#end of script
Question by:DMS-X
    LVL 1

    Author Comment

    Ok lets make this easier. Lets say that I would like to have $TIME be the sysem variable set by executing the command date?
    LVL 1

    Author Comment

    Or better yet how to get and set a variable based on the output of a command within the script it is being run?
    LVL 38

    Accepted Solution

    Hi DMS-X,

       You might want to change two lines:
    USER="user.txt"      ===> USER=`cat user.txt`
    PASSWORD="password.txt"   ===> PASSWORD=`cat password.txt`

      Use "back quote" to execute the comand and pass the result to the variable.


    LVL 17

    Expert Comment

    " Or better yet how to get and set a variable based on the output of a command within the script it is being run?"

    Use backticks.

    MYVAR = `ls -a` would assign the output of ls -a to MYVAR. (Well it does in perl anyway - Im assuming it does in shell as well. Its worth a try.)
    LVL 1

    Author Comment

    That was it. I did try the back quote thing a long time ago but I was using ' instead of ` they look the same gosh darn it. I could have saved myself 500 points and alot of time : )

    Thank you sir wesley!

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Anonabox PRO Tor & VPN Router

    PRO is the most advanced way to fortify your privacy and online anonymity by layering the Tor network with VPN services. Use both together or separately, and without needing to download software onto your devices.

    How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
    If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
    Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:
    Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

    884 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now