• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 459
  • Last Modified:

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

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
DMS-X
Asked:
DMS-X
  • 3
1 Solution
 
DMS-XAuthor Commented:
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
 
DMS-XAuthor Commented:
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
 
wesly_chenCommented:
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
 
owensleftfootCommented:
" 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
 
DMS-XAuthor Commented:
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

2018 Annual Membership Survey

Here at Experts Exchange, we strive to give members the best experience. Help us improve the site by taking this survey today! (Bonus: Be entered to win a great tech prize for participating!)

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now