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
  • 103
  • 1
  • 3
  • 14
  • What are the access rights? (output of ls-l /home/user1/folder/$PROJECT/folder2/folder3/text.log) – L.R. Oct 04 '11 at 19:16
  • -rw-r--r-- "4 more to go" – Dirk Oct 04 '11 at 20:16
  • What does that "4 more to go" mean? More improtant question is - what do you want to accomplish with this modification? – L.R. Oct 04 '11 at 20:47
  • (4 more to go was just SO's character minimum for comments) I want to be able to tail a log upon terminal startup. The path of the file to tail changes from project to project. – Dirk Oct 04 '11 at 21:04
  • Ok, so where does the command entered in "Editing a terminal profile -- Run a custom command instead of my shell Custom command:" end up? Is it in the ~/.bashrc file? – L.R. Oct 04 '11 at 21:47
  • Not sure -- been looking for that too – Dirk Oct 04 '11 at 22:07

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
  • 19,803
  • 6
  • 45
  • 44
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
  • 923
  • 12
  • 20
  • exported -- i take the /home/user1/.../$PROJECT/... into another terminal and it runs fine. – Dirk Oct 04 '11 at 20:11
  • it might be that my profile is not being sourced properly on launch of this terminal window... – Dirk Oct 04 '11 at 20:24
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
  • 6