Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

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

Posted on 2004-10-21
5
Medium Priority
?
450 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
Comment
Question by:DMS-X
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 1

Author Comment

by:DMS-X
ID: 12374736
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
ID: 12374808
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:
wesly_chen earned 2000 total points
ID: 12375236
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
ID: 12375267
" 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
ID: 12375495
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

Featured Post

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I am a long time windows user and for me it is normal to have spaces in directory and file names. Changing to Linux I found myself frustrated when I moved my windows data over to my new Linux computer. The problem occurs when at the command line.…
Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
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.:
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.
Suggested Courses
Course of the Month11 days, 22 hours left to enroll

636 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