/r/shell
News, articles, tips and tools covering shell scripting and command-line interfaces of all flavors.
News, articles, tips and tools covering shell scripting and command-line interfaces of all flavors.
Resources:
Other subreddits you may like:
Does this sidebar need an addition or correction? Tell me here
/r/shell
How can i extract the first occurence of a date in a given .csv file.
example:
file.txt
-------------------
product, | date
Yamaha, 20/01/2021
Honda, 15/12/2021
--------------------
Any help, or maybe some reading i could use to get better at regex?
For Context:
I'm learning Linux for a internship program, and i have quite an amazing task.
Amongst all the steps to get the job done, which involves making a script that copy some file as backup, zips the backup file and creates a report.txt with some info inside and then schedule the script to be run at times. I need to extract expecific data, in a specific position at a file.
My first thought was that i could do something like this .
head -n 2 file.csv | tail -n 1 | grep -e "regexp"
Which would capture the first product, pipe to a grep and the regex would spill out only the date, buuuuut. I suck at regex.
The thing is, i am struggling so much with learning regex, that all i could do at this point was this regex...
^([0-9]{2}[\/]{1}){2}([0-9]{4})$
Which actualy matches the date format, but won't match the full string piped through, and won't capture the group with the date. This regex would only work if i pass in just a date "00/00/1234"
For variables and functions in Bash, the naming conventions seems to be snake_case. Is this also the case for all constants in Bash?
Or are primitive constants (like int, string) always SCREAMING_SNAKE CASE and non-primitive constants (like arrays) use snake_case?
Hello everyone!
I want to introduce my current project crazy-complete.
It is a tool that generates shell auto-completion files using a single configuration file.
Key Features
Other Features
If you're tired of maintaining completion scripts for different shells, crazy-complete may be for you.
Even if you decide against using generated scripts, the output of the tool may serve as an inspiration.
Let me know what you think. If you need support or have any questions or improvement-ideas, don't hesitate to ask!
And if you like the tool, please give it a star on GitHub
We need to ensure that both instances of $RANDOM are treated as a single evaluation. We need to inspect the evaluation process. An approach that captures the internal evaluation
Do you have any idea?
I dont understand why i cant change certain file permitions (i can change some but not all).
I tried running sudo but it cant find the command and i cant seem to instal sudo with "su -".
Im running "git bash" on a windows... I also have 2 users, one personal, one for coding. Might it be the user settings? If so what and how do I change it... No one in my cluster has any info, help 💀🙏
Hi, I'm just curious: what does this mean?
I know it's telling the machine to use bash, but like, why is it a "#!" for example? How/why was it decided that way?
On a road trip to Dallas, TX, we stopped at a Shell (the gas station) in Arkansas to hot to the bathroom. There was fucking BARNACLES on the SINK. BARNACLES! My hands felt dirtier after washing. Words cannot describe how infuriated I was, and still am, despite the encounter being a week ago. I needed to vent about this. This is not clickbait. This is REAL. Never going to a shell again.
Hi, new to coding just started studying shell.
Cant seem to change this files permitions, what am i doing wrong?
(i need to give g and o x permition, have already tried numeric and symbolic methods)
I need to know everything the pc is doing, for example I need to read it and be able to copy and paste the text to activate it, for example the if any app is open and anything I do on it I can see and still copy and paste to do the same, yes I know it's very weird, but if you smart guys or girls know I would love to know, sorry I didn't explain it well
shell script-1 :
#!/bin/bash
cd /(path)/DB/test
for line in $(cat ./test_list.txt); do
./../batch_download.sh -f ./${line} -p &
done
I closed the terminal, but the execution didn't stop. I checked, it is truly downloading files.
However,
shell script-2:
#!/bin/bash
cd /(path)/DB/test
./../batch_download.sh -f ./entry0.txt -p
I cannot close the terminal.
Hi All
I have implemented a unit test for a Shell using shellspec. And I am always thrown the above error in 'before all' and 'after all' both. Even though the log contains exit code 0 which basically indicating there is no error none of my tests are executing.
I have added extra logs and also redirected the errors but still I am facing this error and am out of options. I am using the latest version of Shellspec as well.
I am mocking git commands in my test script. But it is quite necessary for my tests as well.
I even checked for the relevent OS type in the setup method
# Determine OS type
OS_TYPE=$(uname 2>/dev/null || echo "Unknown")
case "$OS_TYPE" in
Darwin|Linux)
TMP_DIR="/tmp"
;;
CYGWIN*|MINGW*|MSYS*)
if command -v cygpath >/dev/null 2>&1; then
TMP_DIR="$(cygpath -m "${TEMP:-/tmp}")"
else
echo "Error: cygpath not found" >&2
exit 1
fi
;;
*)
echo "Error: Unsupported OS: $OS_TYPE" >&2
exit 1
;;
esac
Any guidance is immensely appreciated.
I recently published a comment about my todo list on HN and a few people asked about it. I decided to do a quick write-up of the simple commands I put together to accomplish this in the shell (zsh in my case but it likely works in bash too).
Asking for a brother who is building tools to help other shell/Terminal layer programmers. Thank you.
No, something different than you think... xz performs up to 2% better on ARM64 than AMD64 with the same settings and I have double checked the version, it is the same! gzip on the other hand... no change at all. Also interesting, xz -1 and AMD64 is WAY faster and better than gzip except memory usage but even 100MByte are pretty tame nowadays. So basically gzip is now superfluous in ever aspect, even on my 1990 Amiga with bash and xz I can unpack those Archives, and faster than xz too. And no, I didn't benchmark the Amiga too. I only remember it from the last time I booted it up.
amd64:
578339776 test
40926066 test.gz1
40024392 test.gz2
39818807 test.gz3
36787548 test.gz4
35988603 test.gz5
35188701 test.gz6
35100687 test.gz7
32072861 test.gz8
31762517 test.gz9
23958376 test.xz1
22207696 test.xz2
21483232 test.xz3
25643828 test.xz4
24781276 test.xz5
24459080 test.xz6
24041684 test.xz7
23434612 test.xz8
22865948 test.xz9
15539300 test.xz9e
arm64: 578339776 test
40926066 test.gz1
40024392 test.gz2
39818807 test.gz3
36787548 test.gz4
35988603 test.gz5
35188701 test.gz6
35100687 test.gz7
32072861 test.gz8
31762517 test.gz9
23515536 test.xz1
21855000 test.xz2
21210096 test.xz3
25397736 test.xz4
24562780 test.xz5
24230096 test.xz6
23841668 test.xz7
23250764 test.xz8
22824292 test.xz9
If you are interested in the rest, the first comma column is i7-6700k, the second comma column is Pi400:
578339776 test
for I in 1 2 3 4 5 6 7 8 9 9e; do for A in 1 2 3; do echo "RUNNING $I - $A"; ( time ( xz -$I <test >test.xz$I ) ) 2>&1 | grep real; done; done
xz -1 1,9 35,9 23958376 test.xz1
xz -2 2,8 49,6 22207696 test.xz2
xz -3 4,4 73,1 21483232 test.xz3
xz -4 5,0 88,9 25643828 test.xz4
xz -5 8,1 143,0 24781276 test.xz5
xz -6 13,2 246,2 24459080 test.xz6
xz -7 15,0 24041684 test.xz7
xz -8 21,5 23434612 test.xz8
xz -9 32,9 22865948 test.xz9
xz -9e 155,4 15539300 test.xz9e
for I in 1 2 3 4 5 6 7 8 9 9e; do for A in a b c; do echo "RUNNING $I$A"; ( time ( gzip -$I <test >test.gz$I ) ) 2>&1 | grep real; done; done
gzip -1 2,8 8,4 40926066 test.gz1
gzip -2 2,9 8,5 40024392 test.gz2
gzip -3 3,0 8,4 39818807 test.gz3
gzip -4 3,7 10,7 36787548 test.gz4
gzip -5 3,8 11,2 35988603 test.gz5
gzip -6 4,6 14,5 35188701 test.gz6
gzip -7 5,2 16,8 35100687 test.gz7
gzip -8 7,8 27,2 32072861 test.gz8
gzip -9 9,2 34,0 31762517 test.gz9
I think that is self-explanatory.
Hello, I am new to scripting and trying to make a script that will make it easier to use yuescript to code with the love2d framework. I am currently facing an issue with the zip command.
yue -t lua src
rm game.love
zip -r game.love lua
love game.love
The probem is that the root is lua directory and not main.lua, using lua/* doesn't seem to work, the rest works as intended
Here is how to customize your boring default terminal to boost your productivity. Discover useful terminal commands for navigation and shortcuts to enhance your terminal experience.
etcsh is an enhanced version of the original tcsh, which is a version of the original Berkeley C shell implementing file name completion and command line editing.
etcsh features the following enhancements and fixes over the original tcsh.
• Function declarations;
• variable assignment from pipes and redirections;
• comments on interactive sessions;
• tell whether stdin
is empty or not;
• variable expansion on expressions corrected;
• piped built-ins are forked;
• missing test
built-in implemented;
• read-write variable flag;
• exit
shall cancel lists.
More is to come. Feedbacks and contributions are much appreciated.
I have written a shell that uses the Python language as the scripting language: it's a shell environment that combines the expressiveness of shell pipelines with the power of python iterators.
It can be used in two major ways:
Obligatory example:
140:/home/redhog/Projects/beta/pieshell >>> for x in ls(-a):
... if x.endswith('.py'):
... print x
...
setup.py
Hi all,
after using fish for about 5 years, I have tried the rc shell. I would like to share my experience so far: rc shell instead of bash or fish. If there are any other rc users in this sub, maybe you can help me with some of the open points (like how to copy the current command buffer or better integration of fzf).
VAR1=123 VAR2=456 VAR3=789
VARIABLES="VAR1 VAR2 VAR3"
for i in $VARIABLES do echo "$i = $$i #something like this
done
Expected output: VAR1 = 123
Hi
I'm sure some of you have ever wished to be able to just easily sync changes from one windows terminal instance to another one, for example a secondary laptop or a work device.
If so, consider adding a thumbs-up or your comment to this feature request, thanks!