Most voted "bash" questions
Bash is a very popular shell (command interpreter). Using the commands provided by Bash itself (built-in Commands) we can perform a series of operations in sequence or create quite complex scripts/programs.
Learn more…291 questions
Sort by count of
-
15
votes1
answer398
viewsWhat does '2>' and '&>' mean in Bash?
I’m starting to study Bash and while analyzing some codes on Github, I came across the following excerpts for creating a Heme: which rbenv &> /dev/null || return $(node -v 2> /dev/null)…
bashasked 9 years, 8 months ago filipelinhares 2,417 -
15
votes4
answers47253
viewsHow to insert a line break inside the echo shell script?
I was wondering if there’s any way to insert a line break inside the echo of the shell script. For example, in the command: echo "Bom dia fulano" I’d like the exit to be: Bom dia fulano I know you…
-
14
votes1
answer5857
viewsWhat is the difference between /bin/bash and /usr/bin/env bash?
I have not much knowledge of shell script, always used /bin/bash, but I noticed other variations: #!/usr/bin/env bash #!/usr/bin/bash #!/bin/bash What’s the difference between them? As far as I read…
-
13
votes3
answers666
viewsIn bash, what is the difference between <, << and <<?
I’m learning now to mess with bash (Ubuntu terminal) and would like to understand the difference between these three operators. I think that < It’s file-related, but I can’t explain what he does…
bashasked 9 years, 2 months ago Wallace Maxters 102,340 -
13
votes2
answers338
viewsHow to pass the value of a variable to uppercase or minuscule?
I have a script that gets a variable when running, for example: ./myscript OLA the content of myscript: #!/bin/bash if [ -z $1 ] then echo "Por favor escolha uma opção:" echo "OLA - Faz qualquer…
-
12
votes1
answer129
viewsHow to extract the path to the file
In a variable that contains the path to a file and its name, the file name can be extracted as follows: #!/bin/bash filenamepath="/caminho/para/ficheiro.pdf" filename=$(basename $filenamepath) Which…
-
11
votes1
answer152
viewsConvert PDF document pages to Jpgs
The following code is working within the desired, where it receives parameters in order to convert all pages of a PDF file into JPG files: ID (natural number) Absolute path (must exist and point to…
-
10
votes5
answers1698
viewsHow can I ask the user for confirmation in a bash file?
I need to display a message in the Console and ask for a confirmation. For example, ask the user to type SIM to continue, and verify this.
-
9
votes1
answer16141
viewsCMD, Powershell, Bash - What’s the difference?
There are differences between them, which? I’m talking about Ubuntu’s Bash. I’m curious because to me they seem to do the same thing!
-
8
votes1
answer426
views -
8
votes5
answers1617
views -
8
votes2
answers1783
viewsUsing variable with the sed command
I have the following occurrence: DirUpload=/var/log find $DirUpload | sed 's/$DirUpload//g' The question is, how to use variable along with sed?
-
7
votes3
answers339
viewsBash - Mysql backups
I rode the script below, to perform backups of three Mysql bases. I would like to know if it is correct. #VARIAVEIS DATE=`date +%Y%m%d-%H%M` HOSTNAME1="xxxxx" HOSTNAME2="yyyyy" HOSTNAME3="zzzzz"…
-
7
votes2
answers3359
viewsDifference between "~" tilde and "/" bar at linux prompt?
I am starting a lower level part, where I will program the part of users, permissions and etc. My first question is ~ and / at the prompt ?
-
6
votes3
answers18812
viewsRunning command with another user within a shell script
I have a shell script that I need to run some commands with a linux user, and some other commands with another user. Something more or less like this: #!/bin/bash echo 'rodando com usuário A'…
-
6
votes3
answers134
viewsPrevent script from following symbolic links
With the script below, a search is carried out for all the accommodations in the indicated directory in order to obtain the email addresses associated with each accommodation: #!/bin/bash # Scan All…
-
6
votes2
answers180
viewsBash, know what board you’re running on
How do I get the path to the directory in which the script in bash is located within the script? #!/bin/bash MINHADIR="caminho/para/onde/estou" # apanhar a diretoria onde estou atualmente…
-
6
votes1
answer180
viewsSelect database record for variable
The code below aims to select a database record and save it in a variable for later use of the data: #!/bin/bash dbName='basedados' dbUser='utilizador' dbPass='password' row=$(echo "select file_id,…
-
6
votes1
answer7588
viewsWhat is an unary operator
Code: #!/bin/bash echo "Digite 1:" read$TESTE if [ $TESTE == 654 ] then echo "Usage: ./pingscript.sh [network]" echo "example: ./pingscript.sh 192.168.20" fi Error message: Digite 1: 321 ./z.sh:…
-
6
votes2
answers174
viewsHow do I create an alias to run multiple commands with git?
I wonder how to create an alias for git that runs the following commands: git add (all modified files) git commit (including a message) git push I tried the following gitconfig setting: [alias] upl…
-
6
votes1
answer92
viewsWhat’s the " operator" on Bash?
i=1 aux=3 aux=$(($aux^$i)) echo $aux #2 Can someone explain me this code?
-
5
votes1
answer713
viewsCMD, Console, MS-DOS and related terms
Well, you have embarrassed all the concepts that I’m going to list below, and I would like to present the definition of these terms, maybe some are synonymous with others and others are totally…
-
5
votes1
answer627
viewsWhat is the difference between reset and clear in Terminal?
In the Terminal, what is the difference between the commands reset and clear? I’m using the Terminal of Ubuntu and apparently the two commands clear the screen.…
-
5
votes3
answers586
viewsFind files containing string and rename
To locate files whose name contains a particular string, we can resort to find as follows: File example: 1429331804.H568641P9577.xxxx.example.com,S=17846:2, Command to locate by xxxx.example.com:…
-
5
votes2
answers3166
viewsHow to get the current path of a . sh script?
On Linux-based systems whenever I need to use the following command: #!/bin/bash BASEDIR=$(dirname "$0") echo $BASEDIR But I read in different places that $(dirname "$0") not supported by Mac OS X…
-
5
votes2
answers80
viewsError in build Ionic framework
Gentlemen, I have migrated to linux and I have a question/problem. I already have the android sdk installed with their respective dependencies installed, I run the android command and open me the…
-
5
votes2
answers1778
viewsWhat is a binary operator
I made a code in bash: #!/bin/bash echo "Digite o arquivo: " read ARQUIVO PROCURA=$(find /home/gabriel -name $ARQUIVO) test $PROCURA -e & echo "O arquivo '$ARQUIVO' não foi encontrado" And when…
-
5
votes2
answers74
viewsList the amount of space occupied by a file type in the terminal
I suspect that the Pcs I use have many files .RData, used by the R program to save data sets. I want to do a cleaning in these files, but without going into directory by directory, on computer by…
-
5
votes3
answers738
viewsWhat is the $() [dollar sign followed by parentheses] for in BASH?
I’ve seen some examples of code in the BASH where it’s used $() to be able to execute a command. For example: sudo chown -R $(whoami) . What this means followed by the enclosed command in…
bashasked 6 years, 2 months ago Wallace Maxters 102,340 -
5
votes3
answers77
viewsIs there a bash iterator equivalent to the python enumerate?
It is common situations in which, to iterate, I need not only the elements of a list, but also their respective indexes. In python, this type of iteration is facilitated with the use of iterator…
-
4
votes1
answer751
viewsShell send error message
I have a running cron task that calls a shell script. This sh file backs up the database and saves it to a folder on the server. So far it’s working. I know that at the time of generating the backup…
-
4
votes2
answers2318
viewsExclude character in a given position?
How do I delete a certain character in a certain shell position? I’ve tried with sed, but I can’t get into position either, just the pattern. ",45123","B23142DHAS675" What I wanted was to erase the…
-
4
votes1
answer266
viewsHow do I send a message to stderr no bash via echo command?
I’m writing some script to deploy an application and need to send status messages to stderr instead of stdout, that command echo makes by default. How to do the command echo send the message to…
-
4
votes1
answer175
viewsProblem with echo` -e`
I’m starting to learn shell script and am doing some simple scripts to train. The script below tests whether whoever is running the script is logged in as root. # !/bin/bash # # This script test if…
-
4
votes1
answer442
viewsHow to use acute accent inside a string in a bash script?
I use the script below to download Audios from google translator to use in a personal program that narrates codes and quantities of my stock. The problem is that the high-pitched "oh" accent of the…
-
4
votes1
answer177
viewsHow to calculate the download time of a website using wget?
I am working on a project where I need to calculate the loading time of a webpage for optimization purposes. I’m using this command: $ time wget -H -p --delete-after melga.com.br 2&>…
-
4
votes2
answers805
viewsHow to define a global alias in BASH?
I’m using the Terminal in the Linux and I’m tired of repeating the same commands all the time. For example, I use a command practically all day, then I create an alias to make things easier.…
-
4
votes3
answers1915
viewsWhat are [ ] bash for?
I’m starting shell script now, and often, reading other people’s programs, I see the use of [] associated with if. For example: if [condition]; then fi I have often seen the use as follows: if…
-
4
votes2
answers7992
viewsFind and Replace Multiple Words Inside a File
I want to develop a script which will replace any words in filing cabinet. I know what I can do with the command(s) below: $ tr 'ABC' '123' < arquivo.txt > novo-arquivo.txt or $ sed…
-
4
votes2
answers295
viewsIn bash, what is the difference between a null string and an empty string?
I wonder if there is a difference in how bash represents variables with null values var= and with empty strings var="" What care should I take when manipulating variables like these?…
-
4
votes4
answers5886
viewsGit bash does not accept paste command
I wonder why git bash does not accept the Ctrl+V command. Every time I have to clone a repository on github I have to type in the whole url!
-
4
votes0
answers36
viewsPassing -Metric compare result to variable - IMAGEMAGICK image
I’m comparing two images using Imagemagick on the LINUX terminal. When I type in the Terminal line this (below) it returns a value to me: $ compare -metric mae 0.jpg 2.jpg null: But I can’t put this…
-
4
votes2
answers4989
viewsHow to run scripts in powershell
I have an extract.sh script that does some things. I have another powershell.sh script that makes the powershell call only. And inside the powershell.sh I pull the extract.sh to run the script…
-
4
votes1
answer200
viewsBash. What’s export for?
Looking at Bash scripts, I realized that variables can be created in the following ways: script1.sh: variable1=Ola export variable2="Ola de novo" Find out more about the difference between these two…
bashasked 5 years, 3 months ago Adolfo Correa 258 -
4
votes2
answers166
viewsWhat does the double-dash stand for in a Bash command?
There is a little time that I use Linux and I know that some commands have arguments that use the - at the beginning of a word. Example: ls -la And some others use two traits, so: php artisan --help…
-
4
votes1
answer126
viewsecho output with % and %
When solving some exercises in Shell Script, I find this script: x="Este texto para teste." echo ${x% *} I confess that, when performing the table test, I could not solve it. When running this…
-
4
votes0
answers46
viewsHow to iterate a recursive array without redundancy?
I have in certain directory thousands of software package files, which in turn has versions, as for example: /var/cache/fetch/archives/python-3.5.0-1-x86_64.chi.zst…
-
4
votes1
answer50
viewsWhy does C syntax work to create variable range limit in bash?
I tried to create a variable limit in a range for a for loop in bash using a function. Follow my code: function tree(){ let var=$1 for i in {1..$var} do echo $i done } tree 5 To my frustration, this…
-
3
votes1
answer377
viewsDefine multiple variables in one row only
I would like to parse a single line and break a string into several variables. In string which I will parse, the default is that each field is separated by a comma. In several lines, the code to do…
-
3
votes2
answers479
viewsHandling dates in AWK scripts
CONTEXT: I have a CSV file from which I want to extract and process some columns. I realized that AWK would be the perfect tool for this and everything was fine until I had to deal with timestamps -…