0

This is about bash under macos Catalina but should run under Big Sur too.

I want to fill a variable with the content of an HTML file and filter it later with grep.

Only I get for the HTML file access denied.

As a test, I use

#!/bin/bash -xv

$cat "./omnikresponse.html"  #(it doesn't matter whether I use the whole path or not).

The file has the following privileges.

16 -rw-r--r--@ 1 la staff 6384 Dec 15 17:23 omnikresponse.html

com.apple.TextEncoding 15

com.apple.lastuseddate#PS 16

com.apple.metadata:_kMDItemUserTags 42

com.apple.metadata:kMDLabel_yjfxnnrt6pupmoito5lwf3xyea 89

com.dropbox.attrs 26

de.codingmonkeys.seestate 92

In the security settings, the terminal has 'full disk access'. The script runs as the user and sits in the same folder as the HTML file. I can set the HTML file to 755 and then I have access but it is not really wanted for security reasons I guess.

How can I solve this? Why do I have to change the privileges for just reading the file?

Lord iPhonius
  • 173
  • 2
  • 11
  • Your program would only make sense, if `cat` is an environment variable, and has been set to a suitable value in one of the child processes. – user1934428 Dec 16 '20 at 13:43

1 Answers1

1

Unless $cat contains the name of a program you want to run on the file, the problem is that the shell (rightly) thinks you are trying to execute this file, as if it were a script or a binary.

In case it's not obvious, the $ you see in many beginners' tutorials is not part of what you are supposed to type into the computer; it is a placeholder for the prompt the computer (or rather the shell) displays when it is ready to receive a command from you in the terminal.

To spell this out, $cat refers to the value of the variable cat; if it is undefined or contains the empty string, your script can be reduced to

./omnikresponse.html

(Points for the quoting, but it's not really necessary here. See When to wrap quotes around a shell variable. If you really wanted to refer to the variable $cat, probably that should have been in double quotes.)

And so in still other words, I'm guessing your script should be

#!/bin/bash
cat ./omnikresponse.html

... which of course doesn't actually make sense to put in a script at all; just type

cat ./omnikresponse.html

directly at the Bash prompt.

(If you are beginner, chances are that you are actually using Zsh, not Bash. The default shell for new users since MacOS Catalina is Zsh; in previous versions, it used to be Bash. But this answer probably works for both. ... If it works. I had to guess several things.)

tripleee
  • 175,061
  • 34
  • 275
  • 318