These are public posts tagged with #shellscripting. You can interact with them if you have an account anywhere in the fediverse.
I've probably tooted about this before, but I don't know why this isn't standard.
It's just so obvious, at least to me. ;)
~ $ type mcd
mcd is a function
mcd ()
{
[[ -n $1 ]] && mkdir "$1" && cd "$1"
}
I think I won't bother anymore with writing (bash) shell scripts that are longer than a few lines. I find the syntax too unintuitive and there are better programming languages like PHP that produce more readable code.
In the last two hours, I translated a bash shell script with ~250 lines to a PHP CLI script. The latter is nearly 400 lines long but definetly more readable and it also has more user-friendly output.
1/2
Interesting #ShellScripting quandary:
(solution below)
I'm uncertain how shells delimit filename variables internally.
I have a shell (bash) function that loops through a set of PDF files, opening them in zathura in a "suckless" tabbed window (so that the PDFs always open within the same window, so I can just hit q
to zip through them one-at-a-time.
Here is my variable declaration:
local files=${*-*.[pP][dD][fF]}
But for simplicity, you could just imagine it to be:
files=*
Then I'm doing a
for f in $files; do
I'm wanting to print a status line for each item viewed, so I have an idea how many more there are to go, so I'm using this:
echo "[[$f]] ($count/$tot)"
And of course, there's a ((count++))
at the beginning of the loop.
But how to get the total ($tot
)??
echo $files |wc -l
will always result in 1
, as does echo "$files" |wc -l
What I ended up doing was just creating a
for f in $files; do ((tot++)); done
One-liner loop before the actual loop, just to get a total.
Is there a better way?
Am I missing something really obvious?
Solution, courtesy of @khm
Use an array!
local files=(${*-*.[pP][dD][fF]})
echo "[[$f]] ($count/${#files[@]})"
Should've made this a long time ago:
function ciglob {
#case-insensitive glob generator
echo "$*" |while read -N1 c; do
case "$c" in
[a-zA-Z]) echo -n "[${c^^}${c,,}]";;
*) echo -n "$c"
esac
done
}
~ $ ciglob "Hello, world!"
[Hh][Ee][Ll][Ll][Oo], [Ww][Oo][Rr][Ll][Dd]!
~ $ ls -ld $(ciglob documents)
drwxr-xr-x 52 ~~~ ~~~ 20,480 Apr 10 11:45 Documents
(Not the most useful example, but I did have a use case in mind when I wrote it ;)
P.S. (This is a valid way to close a parenthesis. Fight me ;)
#bash #ksh #sh #shell #UnixShell #POSIX #PosixShell #ShellScripting
#Example directory: 27a81c6a_06f2_4a0b_82a3_5eeee7ef91e8
h="[0-9a-f]" #hex value glob
for dir in $h$h$h$h$h$h$h${h}_$h$h$h${h}_$h$h$h${h}_$h$h$h${h}_$h$h$h$h$h$h$h$h$h$h$h$h; do
if [[ -d $dir ]]; then
...
#ShellScripting #NoImNOTputtingItUpOnMyGitRepo #UglyScriptJustForMe
Gotta say, I wish #bash had local
/ lexically-scoped functions, rather than having to rely on hacks like:
function widget {
function ___widget_parse {
...
}
...
unset ___widget_parse
}
Something like this (which does not currently work) would be lovely:
function widget {
local function parse {
...
}
}
Вот хэштеги, разбитые по конкретным программам из сборника **"Anticensor File Pack Black Day"**:
### ** Безопасные мессенджеры**
- **Jami** – #Jami #P2PMessenger #Decentralized #Privacy #SecureMessaging
- **Element (Matrix)** – #Matrix #ElementChat #EncryptedMessaging #PrivacyChat #Federation
- **Gajim (XMPP)** – #XMPP #Jabber #EncryptedChat #SelfHosted #PrivateChat
- **Tox** – #ToxMessenger #P2PChat #NoCensorship #SecureChat #AnonComms
- **Briar** – #BriarApp #MeshNetwork #DarknetChat #OfflineMessaging
### ** Анонимный веб-серфинг**
- **Tor Browser** – #Tor #OnionRouting #DarkWeb #PrivacyBrowser #NoTracking
- **Mozilla Fennec** – #Fennec #FirefoxMod #PrivacyFirst #NoAds #OpenSource
### ** Децентрализованные файлы и сети**
- **IPFS Desktop** – #IPFS #DecentralizedWeb #Web3 #NoCensorship #FileSharing
- **IPFS Binaries** – #IPFSNetwork #P2PFiles #InterPlanetaryFileSystem
### ** Терминальные утилиты**
- **Termux** – #Termux #AndroidTerminal #LinuxOnAndroid #HackingTools
- **Termux API** – #TermuxAPI #Automation #ShellScripting #CLI
### ** Шифрование и безопасность**
- **PGP (Pretty Good Privacy)** – #PGP #EmailEncryption #PrivacyTools #CyberSecurity
- **DeltaChat (PGP Mail Client)** – #DeltaChat #EmailEncryption #PGPChat #SecureMail
### ** Антицензура и обход блокировок**
- **Antizapret Proxy** – #Antizapret #Proxy #BypassCensorship #FreeInternet
- **Bol-Van DPI Bypass** – #DeepPacketInspection #DPIBypass #InternetFreedom
Эти хэштеги помогут привлечь внимание нужной аудитории: пользователей, активистов, журналистов, разработчиков и защитников цифровых свобод.
OSS CLI tools appreciation post.
Sure, you use AI tools to generate CLI commands. I use CLI tools to generate AI prompts. We are not the same.
#CLI #FOSS #Linux #Automation #Productivity #DevTools #ShellScripting #AI #Memes
today I learned:
#linux #shell
#ShellScripting #wetter #weather
füge das zu Deiner ~/.bashrc hinzu:
```
wetter(){
curl http://wttr.in/$1
}
```
danach:
(found at https://github.com/chubin/wttr.in)
Je viens d'arriver à écrire un script shell en une ligne de awk pour un projet Kirby bilingue où je dois formater des gros fichiers .txt exportés depuis un tableau de traduction sous forme de tableaux PHP indentés correctement, et ça me rend heureux :
`awk -F$'\t*' '{gsub(/[ \t]+$/,"",$1); print " \""$1 "\" => \"" $2 "\","}' input.txt`
Alors que c’est pas fou hein en soi, mais c’est tellement satisfaisant quand ça marche !
Attend the PHP Tek Conference in Chicago, this May. If you develop Web Applications, you don't want to miss it.
I look forward to seeing you all there!
Welcome to PHP Tek 2025 where we combine leadership,…
Tito#RaspberryPi owners, how do you back up your #RPi?
I don’t have an extra hard drive, so I need to back up to #GoogleDrive. I’ve installed #Rclone and tried creating a #BASH script, but I’m struggling with it.
If you’ve set up something similar or have recommendations for an efficient backup workflow, I’d love to hear them! Bonus points if you know any good courses or resources to improve my scripting skills.
#Linux #Tech #SelfHosted #SelfHosting #RaspberryPiBackup #RaspberryPi500 #RaspberryPiProjects #RPiBackup #RaspberryPiOS #RPiProjects #LinuxBackup #LinuxTips #LinuxCommunity #TechSupport #OpenSource #DataBackup #CloudBackup #GoogleDriveBackup #CloudStorage #FileBackup #Rclone #BASHScript #ShellScripting #ProgrammingHelp #CodeNewbie #LearnToCode #TechSolutions #Automation #techhacks @linux @selfhost @selfhosting @selfhosted
Someone help me out, is this too many? XD
$ alias |wc -l
115
$ typeset -F |wc -l
191
$ typeset -f |wc
2934 8863 80790
I have ask for this before but got no answers so I try again :-)
If you go to a browser on a computer (Vivaldi in my case but I don't think it matter) and click on the url box, you'll notice the url is automatically selected. You can press ctrl-c and this url will be copied to the clipboard.
However, if I go to a terminal and type 'xclip -out -selection primary' I will either get nothing or whatever was selected before. In any cases, not my url.
If I deselect the url and re-select it again, then it works as expected.
What is special about this "one-click automatic selection" that make it different from another normal selection?
Now that #RHEL95 is out, bringing with it #Rust 1.79.0, we can finally update @nu_shell in @fedora and #EPEL #EPEL9 again!
Not quite to the latest `0.100.0` as that requires Rust 1.80.1, but close (this also delays us having to deal with updating dependencies also used by other Rust crates for the time being).
`0.100.0` highlights (these are the things you don't get yet): https://www.nushell.sh/blog/2024-11-12-nushell_0_100_0.html#highlights-and-themes-of-this-release-toc
Updates: https://bodhi.fedoraproject.org/updates/?search=0.99.1&packages=rust-nu
A new type of shell.
www.nushell.shIf you're a #Linux person and using the command "ps" with options like "aux" instead of e.g. "-e" (i.e. options without leading "-"), you likely learned the #Unix #commandline on #BSD or maybe SunOS or Solaris. (Or by someone who grew up with them.
)
In other news: #TIL that (in either variant) the option "j" (e.g. as "ps ajx" or "ps -ej") also shows the PPID (parent PID, only with BSD style options), PGID (process group ID) und SID (session ID).
Have any #Linux users tried this? It's called Swiss File Knife, and is a #FOSS utility available via Sourceforge.
It contains 100 command line utilities of various types.
It downloads to Linux as a single binary and is pretty easy to run and use so far.
Kind of fascinating, too, that it's cross-platform...
I haven't used it much but I'm wondering if it might be simpler than some similar Linux utilities.
Link: https://sourceforge.net/projects/swissfileknife/
#Ubuntu #opensource #freesoftware #kubuntu #ShellScripting #scripting #utilities #manjaro #pclos
Pnut: A Self-Compiling C Transpiler Targeting Human-Readable POSIX Shell - Shell scripting is one of those skills that are absolutely invaluable on especiall... - https://hackaday.com/2024/07/25/pnut-a-self-compiling-c-transpiler-targeting-human-readable-posix-shell/ #softwaredevelopment #shellscripting #transpiler
Shell scripting is one of those skills that are absolutely…
Hackaday