# Safest method to convert "linuxisms" to FreeBSD (symlink or shebang editing)?



## tedbell (Aug 28, 2019)

Just a quick question in regards to converting files (python scripts) written for Linux to use FreeBSD.
For example should I just edit every file from 
	
	



```
#!/usr/bin/python
```
 to 
	
	



```
#!/usr/local/bin/python2.7
```
 or should I just symlink the binary to what it's being called for 
	
	



```
ln -s /usr/local/bin/pyhton2.7 /usr/bin/python
```
?
Thanks


----------



## SirDice (Aug 28, 2019)

This should work for both FreeBSD and Linux, assuming python is in the PATH (it normally is):

```
#!/usr/bin/env python
```


----------



## olli@ (Aug 28, 2019)

The Python folks recommend the following because it is most portable and doesn't depend on the OS. Just make sure python is in your `$PATH`.

```
#!/usr/bin/env python
```
If your script depends on a certain version of Python, you should write `python2` or even `python2.7`. Note that Python 2.x is considered legacy, Python 3 is the default for quite some time. So if you use “`python`” only, you get Python 3 (currently 3.6, to be exact).


----------



## ShelLuser (Aug 28, 2019)

tedbell said:


> or should I just symlink the binary to what it's being called for
> 
> 
> 
> ...


As a rule of thumb: _never_ mess with the base system like this. For the simple reason that these changes could easily be undone after an upgrade which could then break quite a few things. If you need a symlink then dump it in /usr/local/bin. And if that doesn't work then simply change your searchpath.

(edit): of course the better solution has been mentioned above, my answer only covers editing the base system.


----------



## tedbell (Aug 28, 2019)

Awesome. Thanks guys


----------

