Most voted "shell-script" questions
Shell script is a scripting language
Learn more…262 questions
Sort by count of
-
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…
-
8
votes3
answers537
viewsHow to remove the space of "4 980 Raphael" only between numbers
I have a string "4 980 Rafael" and I would like to know how I will remove only the spacing that are between the numbers in shell script.
-
8
votes1
answer97
viewsLinux Shell Script - Difference between $(()) and (())
I’m studying shell script and learned to use $(()) and (()) to make calculations. I understood the difference: while $(()) serves to make a calculation and return the result of it, (()) serves to…
-
6
votes2
answers143
viewsCopy all before the first blank line
I have a file with several text blocks, separated by blank line. Ex.: block1 block1 block2 block3 block3 I need a solution with sed, awk or perl that locates the first blank line and redirects the…
-
6
votes2
answers198
viewsShellscript does not find the directory
I’m starting with shellscript ,I have to checksum some files, so I decided to automate things with a bash script.. I made two scripts, one that uses one ls recursive in the directory set by me and…
-
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
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
votes4
answers9489
viewsHow to call a new terminal from a shell script?
I would like to know how to call a new terminal/xterm from within a command in the shell script, so that the shell script that called the other script keeps running non-stop. Does anyone have any…
-
5
votes1
answer255
viewsgoogle API - gcalcli - error running in a script
Carrying on my problem reported here now I can send events from shell-script directly to google calendar, I made a script to run as scheduled, follow file sms.sh down below #!/bin/bash let…
-
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
votes1
answer1651
viewsHow can I only extract PID from a process?
My idea is to create a simple script that can search the PID of a process and kill it for example. This is what I have done so far but has the problem that when running ps the PID will not be…
-
5
votes2
answers1001
viewsHow to debug shell script in linux?
I’m new to linux, and I’m learning shell script and my question is this:. When I want to debug something in PHP for example, I put a breakpoint in the code and run the same with the debug on, I…
-
5
votes2
answers214
viewsHow to get the result of the gdialog menu selection in the Shell Script variable?
I’m creating a script simple learning where the user should: Enter number that will be saved in the NUM1 variable Enter a second number that will be saved in the NUM2 variable Choose from the menu…
-
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…
-
4
votes2
answers472
viewslinux command - lock folder name/rename
need to give access to an ftp user in the /var/www folder but there are folders there that it cannot access/edit/delete tried a command: #chmod 000 <pasta> almost worked, it does not delete,…
-
4
votes1
answer152
viewsHow to identify in a shell script, which is the Docker command that is running
I created this image (https://hub.docker.com/r/keviocastro/elgg-docker/~/dockerfile/) setting up an environment for a social networking web application. This application requires a link to a Mysql…
-
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
votes1
answer5871
viewsPHP execute sudo command with shell_exec()
I’m having the following problem, I’m on time trying to run a file sh with php using shell_exec for example: echo shell_exec("./example etc etc"); My problem is that it does not perform, is it a…
-
4
votes1
answer1023
viewsTransform String into Shell Script array
I am trying to make a script to backup my database. But I would not need to provide the name of the bases when running the script, but save each base in a different file. My script is like this:…
shell-scriptasked 7 years, 9 months ago Amanda Lima 3,428 -
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
votes1
answer425
viewsHow to Automatically Detect a Captive Portal
I’m making a hotspot on a server with Centos 6 and would like to have mobile phones (android and iOS) automatically recognize that they need authentication as soon as they connect to the network, to…
-
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…
-
3
votes2
answers3338
viewsRecursively rename files to default given in Linux commands
I am trying to rename files by making the default overwriting certain patterns, however, I wanted to do this work recursively and still could not get. -/doc |----- texto1.txt |----- texto2.txt…
-
3
votes2
answers1140
viewsScript to shut down the computer when closing a particular program
How do I create a script so that when the rdesktop window is closed the computer will be shut down?
-
3
votes1
answer753
viewsRegular expressions with grep
I need to extract data from a text and I’m trying to do this using grep. But the way to make use of regular expressions with this command is quite different from what is usually done in Ruby or…
-
3
votes3
answers906
viewsCreate file with run permission
When I create file .sh, i need to give permission for it to run, is there any file that can be configured or comando applied so that I can already create the file with the permission to run?…
-
3
votes1
answer137
viewsHelp with shell script and regular expressions
I am making this shell script code that must go through each line of a text file, and determine whether the sentence is positive or negative according to the IF condition #!/usr/bin/ksh file="${1}"…
shell-scriptasked 9 years ago user35663 39 -
3
votes1
answer550
viewsShell script function
I have a VM and need to run a script remotely on another VM, example: Script is in VM X and I need to run by X in VM Y. #!/bin/bash IP=$1 if [ $# -ne 1 ]; then echo "informe o servidor $1: " exit fi…
-
3
votes4
answers684
viewsVariable interpolation in shell script that returns the output of a function
I isolated a problem from a larger script that I am producing. I basically have a function that returns the current date and time in a specific format. I need every time the variable data_hora is…
-
3
votes1
answer326
viewsShow contents of a file by opening the file with the content string of a variable
I have a problem showing the contents of a file using the following command: variavel="Affonso\,\ I.\ P..txt" cat < "$variavel" And running the same command on the terminal but using no variable,…
-
3
votes2
answers2187
viewsCopy directory from one ssh server to another
I need to copy a directory on a server with a script .sh running on another server. I read about the command scp and saw some examples of use, but did not figure out how I put the password of the…
-
3
votes2
answers437
viewsHide error messages
Consider the following shell script: ping 8.asd.8.8 -c1 -q > /dev/null if [ $? == 0 ] then echo 'ok' else echo 'erro' fi This ping will return an error and this error is dealt with in else right…
-
3
votes1
answer68
viewsPass captured data from a Python code to Shell Script
I would like to know what to do to take this data captured from a DHT11 sensor (Python Code [Temperature and Humidity]) and pass them to a Shell script if umid is not None and temp is not None:…
-
3
votes4
answers2433
viewsCount the number of times a character appears in a string
I need to count the number of times a character repeats itself in a string. For example: How many times the character / appears in the string down below?…
-
3
votes1
answer208
viewsConversion of timestamp epoch file name to date
Expensive; I have a list of files (140 thousand) with date in the format Unix epoch timestamp in the file name. I need to convert each file to match its actual date by changing its name. Example:…
-
3
votes1
answer1339
viewsAutomate enter input in command line while running a bash script
I created a script in bash to automate the installation and configuration of my environment necessary to run my project, but some of the tasks require that the actions are confirmed giving enter, I…
-
3
votes2
answers812
viewsWhat is the dollar sign for before a variable?
I would like to know the function of the dollar sign, and also if it is necessary that the variable is stuck ( no space ) in the equal sign ( = ) and the value of the variable ( GABRIEL ) and why?…
shell-scriptasked 7 years, 9 months ago user62320 -
3
votes2
answers1773
viewsHow to make code include in Shell Script files
How can I perform the following process: Add the arquivoa.sh and arquivob.sh in the arquivoc.sh, and then perform the defined functions within each file archivoa.sh #!/bin/bash echo "Arquivo A"…
-
3
votes1
answer70
viewsUse of % in variables
I can not understand what this symbol serves in a variable, I see its use in some points in codes in SQL, Shell Script, C. For what it serves? For example a use of this symbol in Shel Script:…
-
3
votes1
answer358
viewsGraph of total connections per second during a denial of service attack
I have a network dump (PCAP file) containing slowloris attacks: The following script will show the number of connections per second to IP 192.168.1.2 at port 80: tcpdump -qns 0 -A -r 1.pcap host…
-
3
votes1
answer368
viewsChecklist and Dialog with external file - Shell Script
I need to use the Dialog making a Checklist from an external file, I have so far done the following: dialog --stdout --checklist "Contas de e-mail: " 0 0 0 \ while read line do $line "" on \ done…
-
3
votes1
answer154
viewsbash - How to prevent malicious code execution via input?
I own a script (script.sh) who receives a environment variable: echo $MINHAVARIAVEL But when calling it via terminal, I realized that I can pass commands through this variable, and these commands…
-
3
votes1
answer1092
viewsAutomate a script . sh
I have a Shell Script (.sh) and need to automate it. Could someone help me?? This script copies data from a folder and pastes (converting to another format) into another directory, runs a Python…
-
3
votes2
answers902
viewsIgnore the first line
I am using the following command to organize a file: sort -u arquivo.csv -o arquivo.csv But I need to ignore his first line, in case the header. How can I do that?…
-
3
votes2
answers685
viewsFix invalid command dynamically, no alias required
I’m using GNU bash version 4.3.46. One problem I have when typing commands, is that I often end up forgetting a space between the command and its parameters. Examples: cd.. gitlog When the right…
-
3
votes1
answer91
viewsDiff changing lines
I’m comparing two files, which are updated daily, with the command diff -y in order to obtain two results: The first are the lines that have been modified overnight:…
-
3
votes2
answers1498
viewsConcatenate SH command results on a line
I’m starting to learn Shell Script and I have a question. I’m creating a .sh to take the number of processes running in the OS and export this information in a file .csv. The problem is that I would…
-
3
votes2
answers396
viewsHow to create a shell script that puts an echo at the beginning of each line in a file
I need to create a script that inserts the echo command at the beginning of each line of the file and at the end >> blocodenotes, for example #!/bin/bash ls -l uname -a netstat -tunap I want a…