-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
101 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,60 @@ | ||
# PYBASH DEMO # | ||
# run with either: python run.py or python -m pybash demo.py | ||
|
||
# dynamic interpolation | ||
options = {'version': '-v', 'help': '-h'} | ||
>git f{options['help']} | ||
$git f{options['help']} | ||
|
||
namespace = "coffee" | ||
>kubectl get pods f{"--" + "-".join(['show', 'labels'])} --namespace f{namespace} | ||
$kubectl get pods f{"--" + "-".join(['show', 'labels'])} --namespace f{namespace} | ||
|
||
# static interpolation | ||
git_command = "status" | ||
option = "-v" | ||
|
||
>git {{git_command}} {{option}} | ||
$git {{git_command}} {{option}} | ||
|
||
#TODO: | ||
#a = >echo "hello" >> test.txt | ||
#a = >sort < test.txt | grep "HELLO" | ||
#a = $echo "hello" >> test.txt | ||
#a = $sort < test.txt | grep "HELLO" | ||
#print(f"test: {a}") | ||
|
||
# 1. use inside methods | ||
>echo "SORT TEST\nHELLO WORLD" > test.txt | ||
$echo "SORT TEST\nHELLO WORLD" > test.txt | ||
def cp_test(): | ||
print("1. >cp test.txt test_copy.txt") | ||
>cp test.txt test_copy.txt | ||
$cp test.txt test_copy.txt | ||
|
||
cp_test() | ||
|
||
# 2. simple bash command execution with output | ||
print("2. >python --version\n >echo \\nthis is an echo") | ||
>python --version | ||
>echo \\nthis is an echo | ||
$python --version | ||
$echo \\nthis is an echo | ||
|
||
# 3. set output to python variable directly | ||
out = >cat test.txt | ||
out = $cat test.txt | ||
test_data = out.decode('utf-8').strip() | ||
print(test_data.replace("HELLO", "HOWDY")) | ||
|
||
# 4. wrapped, in-line execution | ||
print((>cat test.txt).decode('utf-8').strip()) | ||
print(($cat test.txt).decode('utf-8').strip()) | ||
|
||
# 5. redirection | ||
>echo "hello" >> test4.txt | ||
$echo "hello" >> test4.txt | ||
|
||
# 6. pipe chaining | ||
>cat test.txt | sed 's/HELLO/HOWDY/g' | sed 's/HOW/WHY/g' | sed 's/WHY/WHEN/g' | ||
$cat test.txt | sed 's/HELLO/HOWDY/g' | sed 's/HOW/WHY/g' | sed 's/WHY/WHEN/g' | ||
|
||
# 7. chaining pipes and redirection- works with all! | ||
>cat test.txt | sed 's/HELLO/HOWDY\\n/g' > test5.txt | ||
$cat test.txt | sed 's/HELLO/HOWDY\\n/g' > test5.txt | ||
|
||
# 8. chained redirection | ||
>cat test.txt | sed 's/HELLO/HOWDY\\n/g' > test1.txt >> test2.txt > test3.txt | ||
$cat test.txt | sed 's/HELLO/HOWDY\\n/g' > test1.txt >> test2.txt > test3.txt | ||
|
||
# 9. input redirection | ||
>sort < test.txt >> sorted_test.txt | ||
>sort < test.txt | sed 's/SORT/TEST\\n/g' | ||
$sort < test.txt >> sorted_test.txt | ||
$sort < test.txt | sed 's/SORT/TEST\\n/g' | ||
|
||
# 10. Glob patterns | ||
$ls .github/* | ||
>ls ./* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
|
||
text = "HELLO WORLD" | ||
>echo f{text} | ||
$ echo f{text} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,4 +9,4 @@ | |
if __name__ == "__main__": | ||
import demo | ||
|
||
print(f"running {demo}") | ||
print(f"~ completed running {demo}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.