0

Hello I'm trying to save a text file(let's call it file.dat (it's a UTF-8 Unicode text) into a variable in a script I'm making. I want to call the file.dat like : ./myscript file.dat (or something similar). Having a command line in code in the form of variable=file.dat won't help.

I'm new to shell so I apologize if the question is not very specific

1
  • var=$(<"$1") should work in bash Commented Oct 17, 2016 at 10:04

2 Answers 2

5

Some thing like this should get you started:

#!/bin/bash

content=$(cat "$1")  # This is how you slurp the content of the file

echo "Content of $1:"
echo "$content"
Sign up to request clarification or add additional context in comments.

Comments

2

Try something like this :

var=$(cat $1)

then var will contain the content of your file

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.