Most voted "shell" questions
This is a program that takes, interprets and executes user commands, appearing on the screen as a command line, represented by a command interpreter, which waits on the screen for user commands. " Shell" is also used to describe applications, including software that is "built around" a specific component, such as browsers and email clients that are themselves "shells" for HTML rendering engines.
Learn more…208 questions
Sort by count of
-
17
votes2
answers14623
viewsWhat is and what is "2>&1" for?
When we want to direct the output in order to execute a command without receiving any information, among which potential execution errors we use: meuComando >/dev/null 2>&1 Effectively…
-
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…
-
12
votes2
answers1195
viewsDifference from #! in the first line of a Python script
For a Python script to be executable on a Linux/Unix-based operating system, it must start with the designated shebang (#!): #! /usr/bin/env python But followed by the same I have seen used two…
-
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.
-
8
votes1
answer426
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?
-
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.
-
7
votes2
answers133
views -
6
votes1
answer4745
viewsRun shellscript on an android mobile
Does anyone know if there is a default app that reads shellscript on android mobile? Has anyone ever tried something like?
-
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
votes3
answers638
viewsHow to run PHP in interactive mode?
How do I run php from the command line without using a script as an argument. Example with script: > php index.php I already know how to execute a certain function or code like this: > php -r…
-
6
votes1
answer91
viewsMini search engine
I am making a mini search system for urls that are stored in a.txt file, one per line, my problem is the performance issue because I have 5000 urls stored (only) and it is already slow in searching,…
-
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
answer92
viewsWhat’s the " operator" on Bash?
i=1 aux=3 aux=$(($aux^$i)) echo $aux #2 Can someone explain me this code?
-
5
votes3
answers2176
viewsCommand to replace characters recursively
I need a command that overwrites a specific pattern on each line of a file as many times as necessary until the pattern is no longer found. For example, in a CSV file, fields are separated by a…
-
5
votes2
answers10495
viewsHow to get the number of processors and cores from the terminal?
How to check the number of processors (Cpus) and cores by the Linux terminal?
-
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
votes2
answers941
viewsScript or command to sum all directories and show full size
I am developing a script where from a text list where will have the name of directories, the script take the name of each directory, show the size of each directory and then the total. Example: I…
-
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
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
votes3
answers80
viewsDeleting parts of a Text
Galera is the following wanted to be able to extract only the name of the user in a Shell SCRIPT but must be through the text I inform. I exactly wanted to display on screen only: meucliente From…
-
5
votes4
answers10576
viewsTo create a folder named after the current date in Windows cmd.exe
What I already have: %date% is the windows variable that stores the current date. When I use echo %date% the value Tue 07/25/2017 is correctly printed. But when I try to do mkdir %date% the created…
-
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
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
votes3
answers8272
viewsHow to call external command with Python?
How can I call an external command in Python, as if it ran in the Unix shell or Windows prompt?
-
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
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
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
answers1414
viewsHow to give automatic permissions in shell script
I have a project that whenever I go up to production or change the development machine I copy and paste the whole folder, only whenever I do this I have to give permissions in this folder and in…
shellasked 10 years, 8 months ago Marcelo Diniz 3,356 -
3
votes2
answers428
viewsProblem with IF Shell Script Syntax
I have the code below: RESPOSTA=$(asterisk -rx "sip show peers" |grep 4003 |awk -F" " '{print $6}') if[["$RESPOSTA" == "OK"]];then echo $RESPOSTA elif[["$RESPOSTA" == "Unmonitored"]];then…
-
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
votes1
answer307
viewsHow to remove an alias in bash?
No bash, how to remove an alias? For example, after doing alias man="man -a", I just want to execute man instead of man -a.
-
3
votes1
answer7210
viewsWhat is the difference between & and && in SHELL?
I’m using the terminal of Ubuntu. I learned a certain command to free the memory, which is : free & sync In another case, I learned something like nohup && After all, what are these two…
shellasked 9 years, 2 months ago Wallace Maxters 102,340 -
3
votes1
answer877
viewsCommand to delete all folders except the three most recent
On my application server, I would like to keep a release history of it. However, I don’t want to keep them all, because we rarely have to do rollback for very old releases. Therefore, I would like…
-
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
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
votes3
answers2128
viewsSend PHP variable to Shell Script
I have a file .sh and it has variables that I need to receive from PHP, follow an example: //variavel 1 que preciso receber externamente NAME="" //variavel 2 que preciso receber externamente DIR=""…
-
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
answers1223
viewsMongo find em array dentro de Collection
Good people, this is my exit with the normal find: { "_id" : ObjectId("57be6168ce98ad853a96282f"), "nome" : "Mercado Padrão", "userId" : "o4wQ2i4Dt7cAMNf9A", "produtos" : [ { "nome" : "coca cola",…
-
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
votes2
answers1210
viewsPython Shell and Django
I know that to open the interactive Python shell, we simply run on the operating system terminal: python But with Django installed, you can also open the shell using the command: python manage.py…
-
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
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…