0

I am trying to do some basic scripting in linux (I am a recent transfer from windows) and I am simply trying to open a directory, create either the .odt or .odp files and then open them in their default programs.

I have tried to use "cat > filename.odt" but then i dont know how to stop the writing processes and proceed to next command.

#!/bin/bash
read -p "What would you like the file name to be: " name
cat > "$name".odt
xdg-open "$name.odt"

I want to just create the odt or odp file and then open it in either of their libre programs.

2
  • 1
    What are you trying to put inside the file? If you just need to create a zero-byte file, just use touch file or simply > file. Commented Sep 30, 2019 at 19:17
  • To just create a file use rather touch "${name}.odt", but I'm not sure this will be a valid odt file, that is, some files need to contain metadata when they're created, even if they're empty, just to be opened. Commented Sep 30, 2019 at 19:23

1 Answer 1

1

If the file is supposed to be blank when you create it you can just use: touch "$name".odt rather than cat. Also you don't need the quotes around the .odt in your last line. Your new file would look like this:

#!/bin/bash
read -p "What would you like the file name to be: " name
touch "$name".odt
xdg-open "$name".odt
Sign up to request clarification or add additional context in comments.

2 Comments

So I tried this and the file creation works but running xdg-open doesnt open the file in libreoffice but only in the standard text editor. The comment on metadata seems to be on the right track for why it did this.
Yes, most likely to open this type of file you need more information inside the file. I'd recommend that if you're going to be doing this continuously, you create a template for the file type and use cp template.odt "${name}.odt" rather than touch.

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.