# tclsh conversion help



## fred974 (Jan 7, 2014)

Hello everyone,

I am trying to convert the following tclsh code into csh

```
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:

```
set var user $env USER
set var path $env PWD
set var home $env HOME
```
 and 

```
set var user $setenv USER
set var path $setenv PWD
set var home $setenv HOME
```

Could anyone help*?*

Thank you


----------



## wblock@ (Jan 7, 2014)

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?


----------



## fred974 (Jan 7, 2014)

Hi,
I am trying to get this script to work in FreeBSD 9.2
http://www.mewbies.com/how_to_customize_your_console_login_message_tutorial.htm

I tried to copy and past*e* it but it complained about the '(' in line 5*.*


----------



## wblock@ (Jan 7, 2014)

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.


----------



## ShelLuser (Jan 7, 2014)

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:


```
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:


```
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:


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


```
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.


----------



## fred974 (Jan 7, 2014)

Thank you guys,

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


----------



## wblock@ (Jan 7, 2014)

Well, there's fortune(6) .  Personally, I don't want to see anything unless I specifically ask for it.


----------



## fred974 (Jan 7, 2014)

T*h*ank you @wblock@.


----------

