Solved

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

Posted on 2004-10-21
435 Views
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
ftp://joe:hippo@myftpsite.com
Where joe and hippo is actually data within 2 different files.
Here is what I am actually getting
click here ----->   ftp://user.txt:password.txt@myftpsite.com   <----- click here

#start of script
#-----------------------------------
FTP="ftp://"
USER="user.txt"                                  ##This is a file with the user name in it
COLON=":"
PASSWORD="password.txt"              ##This is a file with the password in it
AT="@"
SITE="myftpsite.com"

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

    Author Comment

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

    Author Comment

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

    Accepted Solution

    by:
    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.

    Regards,

    Wesly
    0
     
    LVL 17

    Expert Comment

    by:owensleftfoot
    " 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.)
    0
     
    LVL 1

    Author Comment

    by:DMS-X
    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!
    0

    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