python - Do I have to change directories and give permissions everytime I try to run a file directly from Terminal? -
i wrote simple code would open google maps , search address pass attribute.the name of file mapit.py
code is:
#! /usr/bin/env python3 #! python3 import sys,webbrowser a=sys.argv b=a[1:] main=' '.join(b) webbrowser.open('https://www.google.co.in/maps/place/' +str(main))
as can see, designed run terminal. when try run program in terminal:
1 save file on desktop 2 open terminal , change directory desktop 3 pass chmod +x mapit.py 4 enter ./mapit.py harvard university, usa
and works fine.
but there simple way run mapit.py
in terminal without changing directories , giving permissions every time want run file?
to running scripts without changing directory, add scripts' location path. lets dir name mapit/ under home dir:
$ export path=$path":$home/mapit" $ mapit.py
adding ~/mapit path temporary, however. won’t stick across terminal sessions or system restarts. if want make command permanently available on system:
echo 'export path=$path":$home/mapit"' >> .profile
and 1 last thing, when changed permissions dont need change on , on again run script.
Comments
Post a Comment