-
Notifications
You must be signed in to change notification settings - Fork 5.3k
/
Copy pathlinux-and-macos.sh
59 lines (50 loc) · 1.46 KB
/
linux-and-macos.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# ------------------------------------
# Add Path to PATH
# ------------------------------------
# Make sure you use the right profile for your system
$ export PATH="<PATH_TO_PYTHON>:$PATH"
# ------------------------------------
# Add Path-Adding Operation to Profile
# ------------------------------------
# Make sure you use the right profile for your system
$ echo export PATH="<PATH_TO_PYTHON>:$PATH" >> ~/.profile
# Reread profile to see effect in same session
$ source ~/.profile
# ------------------------------------
# Filtering Bad Paths from PATH
# ------------------------------------
# View current PATH
$ echo $PATH
# Output:
# /usr/local/sbin:/usr/local/bin:/usr/sbin:/home/realpython/badpython:/usr/bin:
# /sbin:/bin:/usr/games:/usr/local/games
# View on separate lines by replacing colons with newlines
$ echo $PATH | tr ":" "\n"
# Output:
# /usr/local/sbin
# /usr/local/bin
# /usr/sbin
# /home/realpython/badpython
# /usr/bin
# /sbin
# /bin
# /usr/games
# /usr/local/games
# Filter out certain lines with grep -v
$ echo $PATH | tr ":" "\n" | grep -v 'badpython'
# Output:
# /usr/local/sbin
# /usr/local/bin
# /usr/sbin
# /usr/bin
# /sbin
# /bin
# /usr/games
# /usr/local/games
# Replace newlines with colons
$ echo $PATH | tr ":" "\n" | grep -v 'badpython' | tr "\n" ":"
# Output:
# /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:
# /usr/local/games
# Assign to PATH
$ export PATH=`echo $PATH | tr ":" "\n" | grep -v 'badpython' | tr "\n" ":"`