Comments (3)
We can determine existence of an program with "which", it gives full path to program queried, or nothing is program not exist, also it gives exit status 0 when program found, and 1 if not found, so comparing exit status is propably what we want to use to determine existence of a program.
Example output:
$ which dig
/usr/bin/dig
$ printf '%d\n' $?
0
$ which ifconfig
$ printf '%d\n' $?
1
So I wrote litte test.sh to compare and tell if a program exist:
#!/bin/bash
DIG=$(which dig)
[ ${PIPESTATUS[0]} -eq 0 ] && printf "DIG exist, path: $DIG\n" || printf "DIG unavailable\n"
IFCONFIG=$(which ifconfig)
[ ${PIPESTATUS[0]} -eq 0 ] && printf "IFCONFIG exist, path: $IFCONFIG\n" || printf "IFCONFIG unavailable\n"
Which outputs correctly on mine machine:
$ ./test.sh
DIG exist, path: /usr/bin/dig
IFCONFIG unavailable
from synth-shell.
Snippets to get an IP-number (and only the number) as result, both IPv4 and IPv6 variants:
dig:
IPv4:
dig TXT -4 +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{print $2}'
IPv6:
dig TXT -6 +short o-o.myaddr.l.google.com @ns1.google.com | awk -F'"' '{print $2}'
nslookup:
IPv4:
nslookup -q=txt o-o.myaddr.l.google.com 216.239.32.10 | awk -F \" 'BEGIN{RS="\r\n"}{print $2}END{RS="\r\n"}'
IPv6:
nslookup -q=txt o-o.myaddr.l.google.com 2001:4860:4802:32::a | awk -F \" 'BEGIN{RS="\r\n"}{print $2}END{RS="\r\n"}'
curl:
IPv4:
curl -s https://api.ipify.org
IPv6:
curl -s https://api6.ipify.org
wget:
IPv4:
wget -q -O - https://api.ipify.org
IPv6:
wget -q -O - https://api6.ipify.org
from synth-shell.
Implemented this in 40f9261
It check available programs with which
and then uses first found program and only tries next program if result is empty. Optimally we'd use exit result but so far we rely on result having anything in it and supressing any runtime errors from saving to result.
from synth-shell.
Related Issues (20)
- Installed Font not accessible HOT 2
- wc error
- Synth-shell on Windows WSL HOT 2
- better-ls not listing subdirectory HOT 2
- How to limit the python environment length in the prompt?
- Prompt shows ".." instead of "~" for config dir HOT 1
- Glitched looking name system and directory blocks HOT 3
- prompt looks weird. HOT 5
- The cd command lists wrong information HOT 3
- uE0B0 Triangle Separator Char Border Bug HOT 2
- Unable to install. bash-tools: No such file or directory HOT 2
- Terminal no longer starts up in home directory HOT 2
- Additional built-in visual themes HOT 2
- bug in alias.sh and bashhrc HOT 2
- Greeter bug
- custom prompt only for root kali HOT 3
- Unwated 1px Line around WorkingDir HOT 2
- . HOT 1
- SYSTEMCTL FAILED SERVICES:
- Greeter, 'bc' not found. HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from synth-shell.