Skip to content
Advertisement

Use environment vars with head

I need to use some vars in a script where I use tail and head, my script works when I type it in the terminal but when it is in a .sh file I get this error from the head command:

JavaScript

The error comes from this pipe of my script:

JavaScript

I tried using variables in another script where only declaring it in the terminal worked. A friend of mine told me to do this, it works but I don’t understand why.

JavaScript

Advertisement

Answer

I’m not sure which part you are confused about, but here’s what’s going on. head -n $LINE is expecting an integer so if $LINE is empty then head -n has no idea how many lines you want. Example:

JavaScript

If your question is about why you need to use export ... then that’s a function of your shell. Here’s an example:

JavaScript

It’s explained here:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement