The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks. Use this tag for questions applying to /bin/sh and most compatible shells (ash, bash, ksh, zsh, …).

learn more… | top users | synonyms (1)

0
votes
2answers
7 views

Comparing multiple options in a bash (string)

#!/bin/bash red=$(tput setaf 1) textreset=$(tput sgr0) echo -n 'Please enter requested region > ' echo 'us-east-1, us-west-2, us-west-1, eu-central-1, ap-southeast-1, ap-northeast-1, ap-...
-3
votes
0answers
21 views

I want to shell scripting can anybody assist me on this ? Any website or any online course? [on hold]

I want to shell scripting can anybody assist me on this ...Any website any online course.
1
vote
1answer
24 views

compress all pdf files recursively

i want to compress all my pdf files in an given directory and its sub-directories using ghostscript. I´m stuck using the find command within loops by filename including spaces. Here some example ...
2
votes
2answers
186 views

Renaming using terminal and regexp to remove leading numbers from filenames

I want the following files to be renamed removing the sequence numbers. 01 X.mp3 to X.mp3 02 Add Me In.mp3 to Add Me In.mp3 I am trying with the below rename command. rename -v -n 's/^\d+\s*([a-z]+...
-1
votes
1answer
47 views

How to grep and treat meta character as normal character?

I am trying to recursively find some pattern which contains meta character. Pattern that I searching for is template <int N> I have tried : grep -F -lir "template <int N>" * # ...
21
votes
4answers
35k views

Why doesn't my ~/.bash_profile work?

I'm using Linux Mint. My login shell (cat /etc/passwd | grep myUserName) is bash. After I start my graphical desktop environment and run terminal emulator from it, I could see that .bash_profile is ...
3
votes
2answers
51 views

How can I stop vim from editing directories?

Sometimes I accidentally tell vim to edit a directory instead of a file in it vim directory-name # what I typed vim directory-name/blah.txt # what I meant to type Instead of immediately ...
3
votes
2answers
49 views

Echo the list of process not running

I have developed a script, the script refers to a file to start the required processes on that server. The script times out after 180 secs. At the end of the script I would like to display the ...
1
vote
3answers
89 views

How complex can a program be written in pure bash? [on hold]

So after a very quick research, it seems bash/shell (whatever it is called) is a Turing-complete language : https://en.wikibooks.org/wiki/Bash_Shell_Scripting#What_is_Bash.3F I wonder, why is the ...
0
votes
2answers
895 views

Difference between 'echo' and 'echo -e' [closed]

What is the difference between echo and echo -e? Which quotes (" " or ' ')should be used with the echo command? ie: echo "Print statement" or echo 'Print statement'? Also, what are the available ...
4
votes
3answers
869 views

Unicode text doesn't appear correctly in shell

I'm using the terminal in Kali Linux and I try to type Arabic text the characters are shown but separated (appearance not correct) This what my shell shows me ex. لا ا ل ه ا لا ا ل ل ه, which should ...
7
votes
2answers
370 views

Is there a way for shell script to know which program has executed it?

In *nix world, is there a way for shell script to have information about which program has executed it? Example: /path/to/script1 /path/to/script_xyz in this imaginary scenario, script_xyz would ...
5
votes
2answers
60 views

How to set an alias across all tty shells?

I set an alias in shell tt2 but it won't work in other tty shells, any idea how to make a system wide alias ?
2
votes
6answers
132 views

Renaming files from upper case to lower case

I need to elaborate a little bit more. These commands are actually for a BBS FTN tosser. The configuration file for which these commands reside in, only allow specific declarations. Here are a few ...
6
votes
2answers
378 views

Why does changing $PATH affect child shells, but changing $foo not?

$ unset foo $ unset bar $ echo $foo $ echo $bar $ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games $ foo=a $ bar=b $ export bar $ echo $foo a $ ...
4
votes
1answer
73 views

Exploit in bash script parameter possible?

I want to pass an e-mail address from a web form to a bash script. I'm using the following regex: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/ Is this sufficient? Or could one embed an exploit?...
7
votes
1answer
158 views

Why does OS X `install` errors on redirected input when the same version of `install` on linux works fine?

I would like to use install command in order to create a new executable file with pre-populated content (e.g. with single pwd command in it). So I've extended this example which creates a new empty ...
7
votes
4answers
669 views

OpenSSH - map aliases in ~/.ssh/config to IP addresses in command line

Is it possible to query ~/.ssh/config in the command line? Let's say I would like to retrieve what IP address does the particular alias point to in a separate program, is it possible?
2
votes
1answer
59 views

Why do my single quotes vanish on substitution with sed

What is the right command for: sudo sed -i '/, false);/adefine( 'WP_MEMORY_LIMIT', '64M' );' /var/www/html/wp-config.php The result is: define( WP_MEMORY_LIMIT, 64M ); instead of the desired: ...
20
votes
6answers
30k views

In linux, how to delete all files EXCEPT the pattern *.txt?

I know how to delete all txt file under current directory by rm *.txt. Does anyone know how to delete all files in current directory EXCEPT txt file?
2
votes
2answers
579 views

How to control buffering of pipes in bash scripts?

I need my script to be executed with stdbuf -i0 -o0 -e0 otherwise user will wonder why there is no output (becuase of pipe buffer). How can I acheive it? #!/usr/bin/stdbuf -i0 -o0 -e0 /bin/bash ...
1
vote
1answer
97 views

tail file from remote server and nslookup on local

I need a script for resolve hosts. For now I run this script on local machine for i in `tail -F access.log | awk '{print $8}' | awk '{gsub("http://|/.*","")}2' | awk '{gsub("http://|:.*","")}1' | ...
1
vote
1answer
32 views

cat into stdin then pipe into program keeps forked shell open, why?

I'm not sure what's going on but I've been trying to understand what is happening with the input and output. So here is my program. #include <stdio.h> #include <stdlib.h> int main(){ ...
28
votes
7answers
4k views

Why does [A-Z] match lowercase letters in bash?

In all shells I am aware of, rm [A-Z]* removes all files that start with an uppercase letter, but with bash this removes all files that start with a letter. As this problem exists on Linux and ...
35
votes
7answers
3k views

Is `~/Documents` a relative or an absolute path?

This is merely just a vocabulary question, but which keeps turning around in my head. It comes from a practice exam from a LPIC preparation book. The correct answer according to the book is that ~/...
5
votes
2answers
389 views

Shell script: if multiple conditions

I want to create a shell script that echos something if 3 directories don't exist. Here is the code I wrote: test.sh: if [ ! -d "/home/unix/POSTagger2" ] || [! -d "/home/unix/POSTagger2/stanford-...
0
votes
1answer
25 views

What is Alternative of initlog (present in RHEL5) but deprecated in RHEL6?

I am using initlog tool in a cron file to write the output of ntpq -p command in syslog.. But initlog command has been deprecated in RHEL6. Now, I want know the alternative of initlog command in ...
78
votes
3answers
9k views

Why is using a shell loop to process text considered bad practice?

Is using a while loop to process text generally considered bad practice in POSIX shells? As Stéphane Chazelas pointed out, some of the reasons for not using shell loop are conceptual, reliability, ...
1
vote
1answer
34 views

How to set a path variable without root acess? [duplicate]

My college currently uses a very old (like 3 years old) openJDK 1.7 distribution. And being a student, obviously I don't have root privileges. I wanted to use a much later version downloaded a much ...
0
votes
1answer
13 views

How to list SVN repository name with latest revision number

I want to get for each of my SVN repository its latest revision number. My command looks like currently like this: ls | xargs -n 1 svnlook youngest This prints a list of revision numbers. But I'd ...
0
votes
0answers
18 views

Input Return Key In A Sql script

I have a sql script which when run prompts me to input a value, if i don't input any value and press the enter/return key it will select the default value and will pull all the records. I am trying to ...
16
votes
5answers
14k views

Check if pipe is empty and run a command on the data if it isn't

I have piped a line in bash script and want to check if the pipe has data, before feeding it to a program. Searching I found about test -t 0 but it doesn't work here. Always returns false. So how to ...
1
vote
3answers
163 views

Spaces in assignments in shell scripts

What is the difference between a. var=23 b. var =23 c. var= 23 d. var = 23 There is difference in space around the assignment operator. I am new to unix.
2
votes
2answers
35 views

how to check variable existence and compare with the string in busybox?

I want to use something like that if [[ ! -z "$ENV" && $ENV == 'production' ]]; then echo "production"; else echo "dev"; fi but in BusyBox it does not work :( sh: 1: [[: not found It ...
11
votes
3answers
6k views

find with -execdir

When I run find with -execdir I don't get the results I was expecting. For example: mkdir -p a/b/c find . -type d -execdir touch foo \; $ tree a a ├── b │   ├── c │   └── foo └── foo Directory c ...
18
votes
4answers
2k views

What's the difference between eval and exec?

eval and exec are both builtin commands of Bash (1) that execute commands. I also see exec has a few options, but that is the only difference?
-3
votes
2answers
168 views

Find the number of files with sizes

Find the number of files with sizes > 100KB in /, /bin, /usr, /usr/bin and /usr/sbin directories and output them in a two column format with the name of the directory and the number of files.
-10
votes
2answers
221 views

replace the the first line of all .sh files in a folder

Create list of all .sh files in current folder. Check first line of each file in this list and if file starts with #!/bin/sh then replace that with #!/bin/bash. Only modify files that have #!/bin/sh, ...
22
votes
4answers
37k views

Pass shell variable as a /pattern/ to awk

Having the following in one of my shell functions: function _process () { awk -v l="$line" ' BEGIN {p=0} /'"$1"'/ {p=1} END{ if(p) print l >> "outfile.txt" } ' } , so when called as ...
2
votes
1answer
39 views

Is aliasing over a coreutil command a bad idea? [closed]

I frequently find myself copying large directories and then thinking "darn, I should've used rsync instead of cp for this because I can get progress updates". I'm considering adding this to my ....
1
vote
3answers
3k views

Extract the base file name from a URL using bash

url=http://www.foo.bar/file.ext; echo ${url##/*} I expected this code to print file.ext, but it prints the whole URL. Why? How can I extract the file name?
-3
votes
0answers
32 views

sed replace string in file with shell

Line in the file : def customerName = "TEST" Want to replace the TEST by the script argument input($1). Shell Script: The command which is giving TEST as output is : strReplace=`cat $filePath | ...
0
votes
1answer
61 views

Read Input From Command Line

Trying to use the "read command" to accept user input from the command prompt itself but my script doesnt seem to be moving forward echo "Do you want to continue?(yes/no)" read -p $1 if [ "$1" == "...
0
votes
1answer
43 views

Undo last command possible? [duplicate]

In windows you can undo an operation if you press CTRL+Z. E.g. you delete a file in the gui then press CTRL+Z and the file will be restored and appears in the folder again. Is there something similar ...
3
votes
2answers
46 views

Problem with spaces when used in find command

I'm trying to place a zip file with the content of the directory in each directory that doesn't contain any subdirectory. The following command works if there's no space in dirnames and/or filenames ...
1
vote
1answer
32 views

store file with invalid characters

Some files we get from a customer could not be processed properly because they were declared as US-ASCII but contained invalid characters. In order to validate a software fix, I am trying to copy ...
2
votes
1answer
362 views

Define custom login shell in schroot

According to the schroot man page: schroot allows the user to run a command or a login shell in a chroot environment. If no command is specified, a login shell will be started in the user's ...
16
votes
5answers
1k views

How to trick a command into thinking its output is going to a terminal

Given a command that changes its behaviour when its output is going to a terminal (e.g. produce coloured output), how can that output be redirected in a pipeline while preserving the changed behaviour?...
2
votes
2answers
166 views

Need special validation for shell script

I want to create a bash script which will have lot of options while executing. # script.sh --dry-run --user <parameter1> --pass <parameter2> I heard about getopt option but looks like ...
1
vote
1answer
37 views

Segmentation fault when calling a recursive bash function

I have hundreds of multiple folders which contains thousands of zip files which contain nested within the zip files like show on three below start tree structure 012016/ ├── 2016-01 │   └── 2016-01 │ ...