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'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"
}
(((Ok, I'm going to ELI5 this for you (gladly), but you really gotta read it all carefully, ok?)))
Very simple:
function mcd() {
[[ -n $1 ]] && mkdir "$1" && cd "$1"
}
First of all, you've got the function declaration itself:
function mcd() {
...
}
Then the guts:
[[ -n $1 ]] && mkdir "$1" && cd "$1"
The && are a logical and, basically "do the next thing if the previous thing completed successfully. So you could read it as:
if [[ -n $1 ]]; then
if mkdir "$1"; then
cd "$1"
fi
fi
The [[ -n $1 ]] basically means "return true if variable $1 (first argument) isn't blank."
And you already know what mkdir and cd do. ;)
@dmoonfire @sotolf @hyde @joel
Powershell uses the dollar sign for variables? That's a marked improvement over %CURSED% or whatever the predecessor used ;)
DOS Batch was so weirdly limited. It was frankly painful.
@sotolf @dmoonfire @hyde @joel
I might be the only one, but I'm a little sad that #RokuLang dropped the thing where "@array" becomes "$array" when referencing a scalar element from Perl.
But don't anyone take that as a serious criticism. I haven't tried roku yet and haven't so much as touched a Perl script in a couple years.
Used it a fair bit in the naughties, though. Still have a fondness for it, but I'm out of practice.
@rl_dane @dmoonfire @hyde @joel
PowerShell is surprisingly good at doing windows stuff, it still uses @ to create hashmaps if I remember correctly And a lot of $ everywhere :p
$curIln = $file.FullName.Split('_')[1]
$kunde = ''
if ($ilns.Contains($curIln)) {
$kunde = $ilns[$curIln]
} else {
$kunde = $curIln
}
# Gruppe erstellen wenn nicht vorhanden, und dann zu kundengruppe hinzufΓΌgen
if (!$knd_grp.Contains($kunde)) {
$knd_grp[$kunde] = [System.Collections.ArrayList]@()
}
$knd_grp[$kunde].Add($file)
@sotolf @rl_dane @hyde @joel PowerShell does a lot of things right. I like the ability to pass objects instead of purely text, that is awesome.
And you can use / for path separators instead of always needing \.
I do not like that backticks are the escape character instead of \.
I do not enjoy using the language for bigger projects though. We've had a reasonable large system that I've trimmed down over the years to only a few 10ks worth of LOC.
@dmoonfire @rl_dane @hyde @joel
10ks of lines are huge powershell scripts yeah, mine are mostly just for smaller tasks, like parsing some automated mails or files and then send mails and stuff like that. I don't think I've written anything more than 3-400 lines in a script, I really believe when you come up in the ks it could get unweildy quite quick yeah :)
@sotolf @rl_dane @hyde @joel It's gotten a lot smaller than it used to be.
$ tokei
===============================================================================
Language Files Lines Code Comments Blanks
===============================================================================
C# 7723 1556305 1123506 184816 247983
PowerShell 151 12998 9314 1890 1794
SQL 16247 9019795 7701471 703960 614364
... removed a lot of lines
===============================================================================
Total 31510 26172744 24008789 1256384 907571
===============================================================================
@sotolf @dmoonfire @hyde @joel
Same. It's like if really old POSIX shell and BASIC had a really unhealthy child.
@rl_dane @dmoonfire @hyde @joel ah found it :p behold and admire :p
set WINSCP_RESULT=%ERRORLEVEL%
if %WINSCP_RESULT% equ 0 (
echo Success
) else (
echo Error
)
pause
for /f "tokens=2 delims==" %%a in ('wmic OS Get localdatetime /value') do set "dt=%%a"
set "YY=%dt:~2,2%" & set "YYYY=%dt:~0,4%" & set "MM=%dt:~4,2%" & set "DD=%dt:~6,2%"
set "datestamp=%YYYY%-%MM%-%DD%" & set "timestamp=%HH%%Min%%Sec%"
@sotolf @dmoonfire @hyde @joel
That's actually more readable and understandable than I remember. XD
Having to call a commandline option to for is pretty cursed. XD
@rl_dane @dmoonfire @hyde @joel
I also especially wrote it to be as readable as I could as I know if it would ever fail I wound have to try to understand it.
Yeah, I really enjoy the command line option for for as well ;)
@rl_dane I also have something like this called "mkdircd" 
More gems I use a lot:
- wping()='curl -Lv "$1"' > /dev/null'
- dctl='systemctl'
- dctlu='systemctl --user' (yes I run some of my own background services + regular miantenance on systemd, bring in the pitchforks
)
Ooo, I like wping!
about curl, have you seen
https://hurl.dev ?
Looks interesting, although I must admit I'm kind of a dinosaur when it comes to web stuff, and didn't quite understand it.
That's why you'll see me doing silly stuff like web scraping using sed. XD
Now that I think of it, using netcat would probably be a more efficient implementation of wping, such as
function portcheck {
nc -zw1 "$1" "$2" &>/dev/null
}
function wping {
local port successports=() host="${1:-}"
for port in 80 443; do
portcheck "$host" $port && successports+=($port)
done
case ${#successports[@]} in
0) echo "$host is down"; return 1;;
1) echo "$host is up (port ${successports[@]})";;
*) echo "$host is up (ports ${successports[@]})";;
esac
}