tclsh conversion help

Hello everyone,

I am trying to convert the following tclsh code into csh
Code:
set var(user) $env(USER)
set var(path) $env(PWD)
set var(home) $env(HOME)
So far I tried the following but without much success:
Code:
set var user $env USER
set var path $env PWD
set var home $env HOME
and
Code:
set var user $setenv USER
set var path $setenv PWD
set var home $setenv HOME

Could anyone help?

Thank you
 
This is actually tclsh.

It looks like it is reading the values of environment variables and saving them in local variables. A standard shell script could just use the values directly.

Why are you converting it? And why to csh(1), which should not be used for new work?
 
Rewriting that script is going to be a non-trivial job for not much gain. If you really want it, installing lang/tcl86 just to get tclsh may be the easiest way.
 
I took a quick peek at the script but it's a bit too 'weird' for my liking to actually dive into this. Even so, as to the original question, the tcsh(1) manualpage is your friend here. However, the solution may not be this simple.

To set those three environment variables you'd use the setenv command. So instead of the lines used you could use something in the likes of this:

Code:
setenv user ${USER}
setenv path ${PATH}
setenv home ${HOME}
But you're not done here. The script also needs to be changed at the places where it's actually using these newly set variables. For example:

Code:
set lastlog [exec -- lastlog -u $var(user)]
This actually provides us with multiple problems, and it also clearly shows why setting this up may be a completely fruitless effort. For starters; FreeBSD doesn't know the lastlog command, that's a specific command for Linux environments; it shows the last entries from the /var/log/lastlog file. Of course we could try using last(1) instead but I have no idea if that'll provide the required results.

Another reason why this won't work too well; not only is $var unknown, tcsh doesn't use those brackets for command substitution. So this would require a complete change, something like:

Code:
setenv lastlog `last ${user}`
But that of course leads up to yet another new problem:

Code:
set ll(1)  [lindex $lastlog 7]
set ll(2)  [lindex $lastlog 8]
set ll(3)  [lindex $lastlog 9]
set ll(4)  [lindex $lastlog 10]
set ll(5)  [lindex $lastlog 6]
My suggestion would be to quit while you're ahead. This script is too specific to be easily used, not only specific to a particular shell (one which I'm unfamiliar with) but also to the Linux environment. Considering it's functionality I'd consider it a better idea to simply write a script yourself.
 
Thank you guys,

I'll leave it as it seems to be way above my current skill set. Do you guys have something similar that would show me that information when I log in?
 
Back
Top