Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
What are the access rights? (output of ls-l /home/user1/folder/$PROJECT/folder2/folder3/text.log) –  L.R. Oct 4 '11 at 19:16
    
-rw-r--r-- "4 more to go" –  Dirk Oct 4 '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 4 '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 4 '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 4 '11 at 21:47
show 1 more comment

3 Answers

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 paramter -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. Read this answer for some explanation of the difference.

share|improve this answer
add comment

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)

share|improve this answer
    
exported -- i take the /home/user1/.../$PROJECT/... into another terminal and it runs fine. –  Dirk Oct 4 '11 at 20:11
    
it might be that my profile is not being sourced properly on launch of this terminal window... –  Dirk Oct 4 '11 at 20:24
add comment

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.

share|improve this answer
    
Nope; it now prints out .../${PRJ_NAME}/... :) –  Dirk Oct 4 '11 at 21:05
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.