A facility for storing useful scripts for general use?
LQ Suggestions & FeedbackDo you have a suggestion for this site or an idea that will make the site better? This forum is for you.
PLEASE READ THIS FORUM - Information and status updates will also be posted here.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
A facility for storing useful scripts for general use?
Today I found two useful scripts on the first page of "Latest posts". One invoked Google Translate to translate strings from the command line (the actual script was in a linked blog), and the other was a wrapper for a fingerprint reader to turn it into a screen-unlocker. Sadly, these will gradually disappear from sight as more threads are added.
It would be nice to have a little repository where such gems can be stored.
@hazel
Most basic little translator in bash. Needs curl. You could also use wget.
trans.sh
Code:
#!/usr/bin/bash
agent="Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:110.0) Gecko/20100101 Firefox/110.0"
echo -e "\nGoogle Translator\n"
echo -e "For language abbreviations look at: "
echo -e "https://developers.google.com/admin-sdk/directory/v1/languages\n"
read -p "Enter input language: " inLang
read -p "Enter output language: " outLang
read -p "Enter phrase to translate from "$inLang" to "$outLang" :" phrase
phrase=${phrase// /+}
url="http://translate.googleapis.com/translate_a/single?client=gtx&sl=${inLang}&tl=${outLang}&dt=t&q=${phrase}"
echo -e "\nThis is the google api url: "$url"\n"
curl -A "$agent" "$url"
Example usage:
Code:
bash ./trans.sh
Google Translator
For language abbreviations look at:
https://developers.google.com/admin-sdk/directory/v1/languages
Enter input language: de
Enter output language: en
Enter phrase to translate from de to en :Ich habe Probleme mit dem Programm awk, um den zweiten Treffer eines Strings auszugeben
This is the google api url: http://translate.googleapis.com/translate_a/single?client=gtx&sl=de&tl=en&dt=t&q=Ich+habe+Probleme+mit+dem+Programm+awk,+um+den+zweiten+Treffer+eines+Strings+auszugeben
[[["I'm having trouble using the awk program to print the second match of a string","Ich habe Probleme mit dem Programm awk, um den zweiten Treffer eines Strings auszugeben",null,null,3,null,null,[[]],[[["1fdac2347d4ad2bfc63cca9b4fbecbbb","de_en_2022q1.md"]]
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.