Click here to Skip to main content
15,883,901 members
Everything / Programming Languages / Bash

Bash

Bash

Great Reads

by Chris Maunder
A quick overview and a simple bash script to make your script output a little more lively
by Ahmed Khateeb
In this article, I will describe how to Create WordPress Bitnami VM, how to connect to VM, how to add Custom Domain to that VM and important steps to follow after fresh installation.
by Dave Kerr
Text in the command line can quickly get unwieldy. Here are some simple tricks you can use to navigate in the command line.

Latest Articles

by V. Subhash
Compile FFmpeg v7.0 CLI from source and check out some of its new features
by V. Subhash
A simple fix for excessively bright video and low-volume audio
by ToughDev
This post shows a way to change the default crontab editor in bash shell for Raspberry Pi.
by V. Subhash
How to get compile the latest FFmpeg source code and try out some new features

All Articles

Sort by Score

Bash 

7 Apr 2022 by Chris Maunder
A quick overview and a simple bash script to make your script output a little more lively
25 Oct 2016 by Ahmed Khateeb
In this article, I will describe how to Create WordPress Bitnami VM, how to connect to VM, how to add Custom Domain to that VM and important steps to follow after fresh installation.
11 Jun 2017 by Dave Kerr
Text in the command line can quickly get unwieldy. Here are some simple tricks you can use to navigate in the command line.
25 Mar 2018 by Dave Kerr
In this article, I'll show you how you can use the shell as an efficient tool to compliment how you use the clipboard.
6 Mar 2023 by V. Subhash
This final part of the article series covers some other important behaviour of bash, particularly that relating to text expansions and substitutions.
5 Nov 2023 by V. Subhash
A simple fix for excessively bright video and low-volume audio
24 Aug 2013 by Zoltán Zörgő
As Mehdi Gholam stated, it is a programming language and it can be used as shell, but it is quite inconvenient as such. It can be a shell because it has an interactive interface, but it is inconvenient because the main shell commands you normally use in a shell are method calls, it won't let you...
7 Oct 2014 by Sergey Alexandrovich Kryukov
This application should not be in C:. Do you know that a system does not even have to have drive C?!And this is not a "DOS command". In modern OS, there is no such thing.Simply use System.Diagnostics.Process.Start with redirection of...
7 Oct 2014 by Maciej Los
Why to torture yourself by sending some command to the 'command prompt'?Isn't better to use .net classes, objects?Please, see:Network Programming in the .NET Framework[^]NetworkInterface Class[^]Quite often used alternative is WMI[^], which provides functionality to get information...
4 Mar 2018 by OriginalGriff
See here: : colon command for bash - Super User[^]
12 Jun 2018 by Jochen Arndt
It is never a good idea to execute an application when not knwowing what it does (especially by passing command line options). Do such at least as normal user and not as root. With many applications there is a man page installed too. So you should first try if such is available: man scan and...
20 Apr 2021 by k5054
When you use a Here Document, the shell effectively does echo -e "1\n2\n" > /tmp/tempname ./test
21 Jun 2021 by V. Subhash
Cut, copy, convert, mix, rotate, flip, resize, crop, combine, compose, blur, sharpen, smoothen, side-by-side split, PIP inset, fade in/out using FFmpeg Filters
N 14 Apr 2024 by Pete O'Hanlon
This is the type of question that you could probably get answered using something like ChatGPT or Google Gemini. You have the information you want in your question, so what you need to do is write a prompt that will give you a suitable answer....
20 Jan 2012 by Sergey Alexandrovich Kryukov
Use cron or Unix at, please see:http://en.wikipedia.org/wiki/Cron[^],http://en.wikipedia.org/wiki/At_%28Unix%29[^].—SA
24 Aug 2013 by Mehdi Gholam
Python is a programming language : http://en.wikipedia.org/wiki/Python_%28programming_language%29[^]However it can be used within a shell.
23 Jun 2015 by Richard MacCutchan
It is some time since I wrote any bash scripts but I think you may need something like:#!/bin/bash# find all .gz files of 10k since yesterday, and count themcd COUNT = `find . -name "*.gz" -size -10k -mtime -1 -print | wc -l`if [ $COUNT -eq 0...
25 Apr 2016 by Richard MacCutchan
s1= more /home/mohsin/Desktop/system_usage_bash_file | grep TIME | awk 'BEGIN {FS=","} {print $3}'As far as I remember shell scripts, you need to put the command in back quotes thus:s1= `more /home/mohsin/Desktop/system_usage_bash_file | grep TIME | awk 'BEGIN {FS=","} {print...
22 Feb 2017 by Albert Holguin
So, that doesn't appear to be valid bash code, starting a line with "58..62" is invalid, as it's not a command or shortcut... but if it's pseudo-code I'd guess it's attempting to run nslookup on a range of IP addresses.This gets you the same thing that your code appears to be attempting to...
4 Apr 2018 by Jochen Arndt
When you need to include a double quote within a string, you have to escape it as described at PHP: Strings - Manual[^]: exec("sudo tshark -n -r $filename -R rtp -R \"rtp.ssrc == $ssrc\" -T fields -e rtp.payload | tee payloads"); The for loop requires understanding the bash commands: BASH...
21 Sep 2018 by Richard MacCutchan
OK, to continue from my earlier message: 1. "Yes, I did try "redirection" but it did not work as expected." This is one of the most frustrating comments that we see in a question. We have no idea what you did expect to see or happen. And we have no idea what did happen. Without a clear...
1 Aug 2020 by cats n dogs
Hello, i have a list of keys on which i iterate and each time they current is not found in the json object i want to append it to the object. What I have tried: Here is what i have done so far https://jqplay.org/s/risDCfxm5j The problem is...
1 Aug 2020 by p e a k
The key is reduce. The following variant of your jq program produces the output shown below: reduce ("secrets","toto","test") as $k (.; if index($k) | not then . + {($k): $k} else . end) Output: { "config-maps": [ { ...
24 Mar 2021 by k5054
Problem one seems to be a mix of UTF-8 and ASCII quotation marks (") in your code -- assuming you did a cut&paste from your source. Next, your logic is slightly off. You break the while loop and report no matches on the first non-match. One...
16 May 2021 by Peter_in_2780
You probably don't have write permission in /home/otherUser/ , so your attempt to create the file will fail. Check /var/log/syslog for error messages from cron.
18 Jul 2021 by Daniel Pfeffer
Working backwards from the numbers that you give, we get 1 block = 100Mb / 22355 = 4473 bits. This looks close to a 4 Kb (i.e. 512 byte) block size. Adding various header and framing bits make the correspondence even better. I expect that you...
13 Oct 2021 by Peter_in_2780
date2=$(echo $date1 | awk '{print $1 " " $2 " " $4}')
16 Oct 2021 by Peter_in_2780
cert_expiration_epoch=$(date +%s -d "$cert_expiration") You really should start using the basic tools available. date --help man date man bash Also as someone else already told you, it's much better to use $(command) rather than `command`
1 Nov 2021 by Richard MacCutchan
It is because of the uncontinued blank line and the single quotes around $password. The following works*: curl "https://somewebsite.com" \ --request POST \ --header "Accept:application/json" \ --header "Content-Type:application/json" \ --data...
2 Dec 2021 by OriginalGriff
Answered only to remove from unanswered queue - solved by OP.
25 Apr 2022 by OriginalGriff
It's the "^" character, but it must be the last character on the line: it can't be followed by a space or anything else. Try it: WINKEY+R, "cmd" ENTER "cd^" It will respond "More?" "\" ENTER The current directory will chance to root. Yes, it...
26 Jul 2022 by k5054
You can use normal comparison operators inside a bash [[ ]] expresion. Try if [[ $line > 30 ]]; then ... fi
8 Mar 2023 by V. Subhash
How to get compile the latest FFmpeg source code and try out some new features
8 Mar 2023 by k5054
How to update a bash variable inside a loop when reading from command output
7 May 2023 by ToughDev
This post shows a way to change the default crontab editor in bash shell for Raspberry Pi.
4 Sep 2023 by Richard MacCutchan
Try this one: [a-z\-\.]+ You can test regexes online at https://regexr.com[^]
8 Feb 2024 by k5054
Are you sure you have the BinanceCex table in the SQLite file ConfigDB.db? Check your db file $[k5054@localhost]$ sqlite3 ConfigDB.db .schema CREATE TABLE BinanceCex( id int, ... ); CREATE TABLE StampExchange( ... ); $[k5054@localhost]$ Are...
18 Feb 2024 by OriginalGriff
Use string replace: How to Replace Substring in Bash Natively[^] The string to search for: ",] The string to replace it with: "] If the "spare comma" is there, it'll be removed. If it isn't, the string will be unchanged.
23 Feb 2024 by Richard MacCutchan
See https://stackoverflow.com/questions/30358065/syntax-error-bad-for-loop-variable[^]
31 Mar 2024 by k5054
You bash script already seems to print out the URL it sends in send_request(), but I can't see that your python script does the same. The first thing I would do, is get the python script to print out the URL and compare. If you want to see...
U 12 Apr 2024 by V. Subhash
Compile FFmpeg v7.0 CLI from source and check out some of its new features
N 14 Apr 2024 by OriginalGriff
This isn't a "code to order" website - I suggest that if you can't do it for yourself (and are unwilling to learn how) you try somewhere like Freelancer.com - but be aware: you get what you pay for. Pay peanuts, get monkeys.
31 Dec 2011 by Graham Breach
Do a search for "ssh certificate based authentication" - as long as it is enabled, key-based authentication should allow you to use scp between trusted hosts.
20 Jan 2012 by Be Yourself
I have a java class to be scheduled in the server to be run in a specified time .Can any one help me how to schedule a execution of a java class in server .I have tried goggling for it but I didn't find any fruitful results.The server is apache server.
29 Jan 2012 by Be Yourself
I have a jar file named main.jar with the Manifest entry as:Main-Class : tss.ReportClass-Path : lib/Classes12.jar lib/xlist.jar lib/axis2.jarnow I have the lib folder in the same directory as that of the jar file and I am able to run the jar also from command prompt by using "java -jar"...
11 Mar 2012 by zhaoyilong1
My program runs very similar like "cat" command in shellbut I failed to print the messages to file when I try to use dog Hello > inputfileIn my code , I only use printf to print the messages, it works when the stdout is screen, but fails when I try to output to a file..I think...
7 May 2012 by Sicppy
I am making a sort of Stereotypical english to russian translator, when I do: read -p 'Wanna learn russian? Type in an english phrase!: ' ENGecho $ENG | sed 's/ //g'It echoes the sentence perfectly fine with no spaces in the sentence. But when I try to do this:read -p 'You wanna learn...
7 May 2012 by Sergey Alexandrovich Kryukov
Out of curiosity, I tried to see how your sample phrase is translated into Russian, in your original form (slightly fixed) and also its equivalent in formally correct English:Wanna learn Russian? Type in an English phrase!orDo you want to learn Russian?Type in an English phrase!and...
8 May 2012 by Hex01
Instead of:ENG=$ENG | sed 's/ //g'try:ENG=`echo $ENG | sed 's/ //g'`Note that this uses back-quotes after the equal sign and the last character.
4 Feb 2013 by coffeenet
HiI need to input this command, it is written in bash, but I my terminal is zsh. How do I rewrite it?ssh username@rserver.com -L 127.0.0.1:8888:*:11111Thanx!
24 Aug 2013 by Sandra McGarry
I'm getting mixed answers, is Python a shell or isn't it? Python seems easier to understand than Bash but Bash is a "Shell" for Linux. I'm writing a paper about Linux Shells and am confused on this point. I need an answer rather quickly please. Thanks in advance for any help.
25 Aug 2013 by AjithKp560_
Python is not a shell. It is programming language. You can program many exploits using this programming language. So, the exploits that will spawn control over remote computers are also called as "SHELLS". Like this you can program exploits using perl, ruby, php like programming languages......
12 Oct 2013 by Member 10272533
I have some problem with bash script.I've got a string which has some repeated patterns like this.1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4 ...Each fields is separated by tab key.I want it to look like this...1 2 3 41 2 3 41 2 3 4...How can I solve this problem using bash...
14 Oct 2013 by 101zeeshan101
You can use sed like this:Solution:s='1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4'p='1 2 3 4'echo "$s"|sed "s/$p\s*/&\n/g"1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4You can use infinite while loop and use the input file and iterate through each line to use this logic for murtiple lines.Live...
21 Oct 2013 by Andreas Gieriet
The task sounds non-sense to me.Running a process in background means:the stell starts that command as background process (fire and forget) and immediately continues with the next command.I.e. this completes instantly:sleep 100 &echo "done"You may observe the sleep process by...
21 Jan 2014 by Member 10066562
i am working in iPad application automation. Now i am facing a problem that how can i check that my application is running that is automate in iOS Simulator(iPad/iOS 6.1) using bash script. My OS is Mac OS X (Version: 10.7.5). Please help.
24 Jun 2014 by Maciej Los
Have a look here: Sending Emails with Attachments from the Command Line Revisited [^]As per i understand you need to install 2 packages (Email and MTA). After configuration, you'll be able to send email with attachment(s).
26 Jun 2014 by Alexander24
I have installed all the dependencies in cron. My scripts are working properly, and also I have tested cron which I think works properly as well. However, I would like to set up a task to run a script file. Here is where I need help, please can anyone provide me some help? Here is cron code: My...
12 Sep 2014 by nikuuul
I am searching for one file, say "file1.txt", and output of the find command is like below./home/nicool/Desktop/file1.txt/home/nicool/Desktop/dir1/file1.txt/home/nicool/Desktop/dir1/dir2/file1.txtIn above cases I want only common parent directory, which is "/home/nicool/Desktop" in above...
12 Sep 2014 by DaveAuld
I think this answers your question.http://stackoverflow.com/questions/12340846/bash-shell-script-to-find-the-closest-parent-directory-of-several-files[^]
19 Sep 2014 by Anand Shaw
Hi,I want to store welcome message to a file when I do SSH to a unix server.Please tell me how can I redirect the message to a file.Thanks.
19 Sep 2014 by Anand Shaw
Hi,As a user to a linux server, I don't have access to shadow file. But I want to find out password expiry details for my username.Thanks.
19 Sep 2014 by Richard MacCutchan
cat /etc/motd > somefilename
7 Oct 2014 by Jaxam
In a command prompt I can type "ipconfig" and a list of internet information will appears. I want to do this in a C# console program. Basically, I want to run the C# program and I want to read and store everything that is given in "c:\ipconfig"."ipconfig" is a String in which that I can set...
4 Nov 2014 by Robert-68
Hello friendsit is too long time I don't code :-(I'm landed today on this cool community.I need realize (or thank you if you want to provide one) an utility that would count how many blank sectors (blank is meant that for the given sector, each of the 512 bytes is x00) are present in...
10 Nov 2014 by Member 10440553
How do I sed to retrieve URLs within single quotes?Currently, it can only retrieve URLs which starts with HTTP/HTTPS.urls=$(sed -ne 's/.*\(http[^"]*\).*/\1/p' 's/.*\(https[^"]*\).*/\1/p' /url/to/path)
11 Nov 2014 by Member 11224763
Hello,I have a project where I have to show the current temperature on a website.I already created a script in bash that "echo" me the current temperature, but I don't really know how to display that result on my website.Sincerly,Yvan MLS
11 Nov 2014 by Dominic Burford
There may be other ways of doing this, but you could consider using the XMLHttpRequest object as in the example below.xmlhttp=new XMLHttpRequest();xmlhttp.open("GET","temperaure.txt",false);xmlhttp.send();document.getElementById("temperature").innerHTML=xmlhttp.responseText;
29 Jan 2015 by fausthsu
Does WebHDFS support HAR access?I'm programming a remote control script, and I've searched a lot and made some test, seems it does not?thanks.
28 Apr 2015 by Member 11649315
Tried finding an answer on stackoverflow but can't. All answers were with awk and sed which I'm not allowed to use! So once again, I ask you to help me.Basically I need to write a script that prints out the history of all used commands in the linux terminal. The commands are saved in a file...
28 Apr 2015 by Richard MacCutchan
It's a while since I did much bash scripting but you probably need to start by passing the file through sort, to get the commands in sorted order. Pass the sort output to uniq which, I think, has an option to count the lines. Check the man pages of each command for the applicable options.
26 May 2015 by Member 11612625
stuck. very stuck. why? because i can't figure out a replacement command that works by giving an indexwhat i'm doing now is: rpl "oldstring" "newstring" "filename"ofcourse this changes all the search results. what i need is something like this: rpl "index" "newstring"...
26 May 2015 by _Asif_
I have not tried it myself but it seems that this could help you out[^]
2 Nov 2015 by Member 10308543
Hey guys,I am working on an Illustrator extension project which uses HTML5 for UI and JavaScript for implementing functionalities.Apart from HTML5 I am also using JQuery and AngularJS.Illustrator SDK has an special feature where you can execute a process using it.I need to pack a PDF...
11 Nov 2015 by Member 12131950
I have the following directory strucure: project root/ negatives/ the negatives files ngest/ 00palmo/ 1510 positives files 01pugno/ 1431 positive files 02indice/ 1073 positive files 03v/ ...
16 May 2016 by Member 12485314
i want to overwrite value of variable s1 from "abc" to ---> [more /home/mohsin/Desktop/system_usage_bash_file | grep TIME | awk 'BEGIN {FS=","} {print $3}']but when i echo i get "abc" on both echos,means it is not overwrittenWhat I have tried:#!/bin/bashs1="abc"s2="USED"echo...
23 Jul 2016 by magic_owl
for f in ./*.mp3; do sox "$f" "${f%%.mp3}processed.mp3" silence 1 0.02 1% -1 0.02 1%; doneThis is a script I'm using to process audio files. The problem is that it keeps going in a loop, processing the new audio files as well. I'd like to fix this by having the output go in a subfolder, so I...
29 Sep 2016 by Member 12767270
I am learning bash scripting and I am trying to understand how regex works with bash. In my simple program, I have a file of various different lines but want to match a simple int pair with the format of the two numbers separated by a comma and a space as so: 123, 123. I also want to match the...
3 Oct 2016 by Member 12773538
I have a bash script to login into one of my storage device and execute couple of commands and saves output into one text file. Here's the code.plink.exe -ssh root@10.10.10.10 -pw password1 "storage-controllers" >> Cluster1_%date:~-4,4%%date:~-7,2%%date:~-10,2%.txtecho. >>...
23 Nov 2016 by Alexander Mills
I have a node.js script and I want both stdout and stderr to go to a log file, but I want to pass the stdout and stderr through grep first.This works: node a.js > a.log 2>&1But this doesn't:node a.js | grep "error" > a.log 2>&1It doesn't output anything to the file, but worse...
23 Nov 2016 by Jochen Arndt
Just redirect stderr to stdout before piping to grep:node a.js 2>&1 | grep "error" > a.log When using bash, there is a shorthand for the above:node a.js |& grep "error" > a.log With |&, stdout and stderr of the first command are piped to the second. See the Bash Reference Manual[^].
22 Dec 2016 by Member 12917493
Hello everybody,I have been working with Debian for a couple of months for school and because it seems really handy to work with. but now I want to make a game for in the terminal. A Higher or Lower card game (also for school but I wanted to make it before I was given this task). You have to...
22 Dec 2016 by Jochen Arndt
I did not checked all the code but this looks suspicious:if [ "$score" -ge 1 ]; then Number=$(($RANDOM % 52)) Gokkaart=${KAARTEN[$Number]} oldNumber=$Number echo "De kaart is $Gokkaart2"fiYou are assigning a new random number to $Number. So the old number is no longer...
22 Feb 2017 by Patrice T
Quote:58..62A simple search in bash reference manual gives the answer.Since we are not a free search service, you will to find the answer by yourself/1) find Bash reference Manual2) search ".."Advice: If you want to avoid rude answers in future, do at least basic researches before...
5 Apr 2017 by Testieaccou
here is a shell script which takes domain and its parameters to find status code . this runs way faster due to threading but misses lot of requests. if i ran normally it process all requests but the speed is very low. is there a way through which speed is maintained and it also not misses all...
12 Aug 2017 by Rev7
I have a file with the following content 1,000 2,0001 300 4 I am trying to sort it numerically. What I have tried: sort -n filename sort -g filename
17 Aug 2017 by D4rkTrick
How to create a web control panel for sound and lights for your Parrot drone (Wi-fi connected)
4 Apr 2018 by User 13204940
Hi, I found a small bash script to do exactly what I need but I tweaked a few things. Now I've realised I need this in PHP instead. Would anyone mind helping me convert this to PHP please? I've done some parts, but with the "==" parts I'm not sure how that works out. ssrc=$(tshark -n -r...
4 May 2018 by Member 13811640
Hello, I am new to Xlib, so don't know pretty much all of it. :D I would like to create a window frame across the screen, just that, just a window frame (something like the border of the marquee when you select with the mouse). I like that window frame to show up on the screen, let's say in...
22 May 2018 by lukeer
Hi forum, a bash script I wrote behaves unexpectedly (read: "There's a bug in it.") and I just don't get it. Say there's that variable PAGES which contains " page0.pdf page1.pdf page2.pdf". And there is $1 which contains "result.pdf". I want to merge all those single-page pdf files into one...
21 Sep 2018 by Vaclav_
I just started using bash scripting language and having trouble understanding "command substitution " and " redirection". I am using bash man very frequently and know something about this specific subject. Here is an example of using command substitution. I used command "sed" to find line...
22 Sep 2018 by Vaclav_
I have copied the following from LibreOffice and used "best guess" feature to post it. Hope the formatting pass. I am using the following function to output current line of bash -x debug script. echo_line_no () { grep -n "$1" $0 | sed "s/echo_line_no//" # grep the line(s)...
25 Sep 2018 by Vaclav_
This is not a dupe of my previous post, I am asking for help to resolve specific issue now. I am using "sed" with an option "=" to retrieve file line number of first occurrence of pattern specified. The documentation states that "sed option = " OUTPUTs line number(s) where the match of...