1

Redhat Linux Enterprise

Editing a terminal profile -- Run a custom command instead of my shell Custom command:

tail -3000f /home/user1/folder/$PROJECT/folder2/folder3/text.log

When I save it and relaunch, I get:

tail: cannot open `/home/user1/folder/$PROJECT/folder2/folder3/text.log' for reading

When I copy this path directly to another terminal, tailing works fine. Is the custom command auto escaping the $PROJECT variable?

Dirk
  • 113

3 Answers3

2

I assume that you are using gnome-terminal, and that the "custom command" you mention is the custom command which gnome-terminal will run instead of the default shell (usually bash).

Gnome-terminal is a terminal emulator. It has no knowledge of the concept of variables or variable expansion. That is why, if told to execute some string containing $PROJECT, it will do just that, it will not expand $PROJECT. Variable expansion is the work of the shell.

Read the wikipedia articles about terminal and shell to better understand the difference between a terminal and a shell.

If I am correct with my assumption, that you are running gnome-terminal with a custom command, then you should use this custom command instead:

bash -c "tail -3000f /home/user1/folder/$PROJECT/folder2/folder3/text.log"

This will tell gnome-terminal to execute bash with some arguments. The arguments will tell bash to execute the command tail with some arguments. Only this time, before executing tail, bash will expand the variable $PROJECT before executing.

Note that starting bash using the parameter -c will cause bash to not read the initialisation files (.bashrc and/or .profile). If $PROJECT is defined in one of those files then the above command might fail because $PROJECT will expand to nothing.

You can force bash to read the initialisation files by using the -l parameter:

bash -l -c "tail -3000f /home/user1/folder/$PROJECT/folder2/folder3/text.log"

Note that bash has this concept of "login shell" and "interactive shell" with some implications on what initialisation files are read. For more explanation of the difference read the following question and answers: Difference between .bashrc and .bash_profile.

Lesmana
  • 20,621
0

Are you putting that command in a file and sourcing the file or making it executable and executing it like a script? It's possible the environment isn't being passed to the script. Is $PROJECT an environment variable (export'ed or setenv'ed) or is it a variable in your current shell?

If you're using bash or sh, you can try export $PROJECT or if you're using csh/tcsh you can try setenv PROJECT=(the value of $PROJECT)

Jon Lin
  • 991
0

Just a wild guess - try:

tail -3000f /home/user1/folder/${PROJECT}/folder2/folder3/text.log

It uses variable written as ${PROJECT} instead of $PROJECT. Unfortunately I am not able to test it.

L.R.
  • 151