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
3answers
65 views

Why is the array empty after the while loop? [duplicate]

I try to initialize an array in bash-4.2 next way: ring=() ls -las | tail -n +4 | while read line > do > ring+=("$line") > echo ${ring[-1]} > done 3924 -rw-r--r-- 1 username group 4015716 ...
16
votes
5answers
2k views

Root shell mistakenly changed. How can I change it back to a valid shell?

I mistakenly entered chsh -s /usr/bin instead of chsh -s /bin/bash and now I can't log into a root shell, how do I start a bash shell as root manually ?
1
vote
1answer
24 views

Executing shell script parallelly and in background skips some operation

del_client.sh --delete client1 & del_client.sh --delete client2 & del_client.sh --delete client3 & del_client.sh --delete client4 & When I executed the commands above in the ...
-1
votes
1answer
46 views

Unable to execute shell from web server

When ever I am trying to execute php script from web server, it fails: cat test.sh echo "Hello World" [root@yumserver ~]# I am trying to build a button on webpage through which I can push the ...
1
vote
1answer
24 views

Which shells have functions where “local” does not alter exported variables for child processes?

In the example below, an exported variable is re-set as local in a function. Bash, Zsh, Fish don't pass on the original value to the child process. Are there any shells that make local affect the ...
0
votes
1answer
34 views

linux - setting order in which files are read or output with utilities (sorting)

I'm having issues with programs reading files in the wrong order, and also outputting in an undesirable order with utilities such as ls. I've tried some of the LC_COLLATE options, but none of them ...
1
vote
4answers
79 views

How to break a long string into multiple lines in the prompt of read -p within the source code?

I am writing an installation script that will be run as /bin/sh. There is a line prompting for a file: read -p "goat can try change directory if cd fails to do so. Would you like to add this ...
1
vote
1answer
34 views

Bash: How to get a value from an array to create command from it

Is it possible to use bash to fetch a string from an array provided in the following syntax within a config file? | | Version | PackageManager | Webserver | Database | ...
0
votes
1answer
31 views

How to execute a command for all mp3 files in a directory? [duplicate]

I have a directory with some mp3 files. I want to remove (almost) all ID3 tags using mid3v2 <file> --delete-frames=AENC,APIC,... for every mp3 file in the directory. Other files should not be ...
2
votes
5answers
155 views

Have the ls command behave differently based on the number of entries

Is it possible to have the ls command behave differently based on the number of directory entries that may be listed? If I just use ls (with no modifying options, but I can specify directories or ...
1
vote
3answers
160 views

bash / sh script to replace text between some tags/strings in a text file

I am creating executable which will be executed with /bin/sh or /bin/bash script, I have a file which contains a structure like, there will be only one #start and #end tag in the config file, and I ...
0
votes
1answer
64 views

How to run gnome javascript extensions (gjs) from terminal

I created an extension for gnome shell and want to be able to start it using a keyboard shortcut (something like ctrl+space). I didn't find good documentation or tutorials that helped me creating the ...
1
vote
1answer
38 views

Changing Shell to /bin/bash without root access via file [duplicate]

lets assume I am user(with no rights) and I need to change my shell as a default to /bin/bash by editing a file. So where I can find a file for a specific user where I can edit my default shell and ...
2
votes
1answer
31 views

What does [vmuser@localhost ~]$ mean?

What does the vmuser, localhost, ~, and $ mean in: [vmuser@localhost ~]$
1
vote
5answers
54 views

Running commands on several files and giving each output a unique name

I want to run a script on all the files in a folder like this: sh script.sh *.fasta > output however I want the outputs to be in individual files for every input. So instead of getting 5 files ...
3
votes
1answer
40 views

comparing values in separate columns

I've got a csv that looks like this, (there are other columns but these are the pertinent ones) region, city, actual rating, predicted rating NSW, SYD, 0.765, 0.5 Victoria, Melbourne, 4.81225, 5.0 ...
3
votes
1answer
75 views

$_ vs !$. Last argument of the preceding command and output redirection

The question is about special variables. Documentation says: !!:$ designates the last argument of the preceding command. This may be shortened to !$. ($_, an underscore.) At shell ...
0
votes
1answer
34 views

How can I access the history buffer in sh? (not in Bash)

Is there a command history in sh, for example how to access it, and as well, how to ensure it is clear? To clarify shells here: let's say you've logged on to a non-Gui Linux system, and $SHELL is ...
1
vote
2answers
26 views

How prepend appropriate amount of 0's to numbers contained in image names?

I've got a folder /User/me/Desktop/folder/images with files like key 1--name.jpg, key 10--name1.jpg, etc. The files are sorted incorrectly when fed to my site so I get an arrangement like key ...
1
vote
3answers
283 views

Are & and ; unary or binary operators?

About the control operators & and ;, from POSIX 2013: For asynchronous lists, the format for running a command in the background is: command1 & [command2 & ... ] For sequential ...
0
votes
0answers
51 views

Is a pipeline made of simple commands?

From Bash Reference Manual A pipeline is a sequence of simple commands separated by one of the control operators | or |&. From POSIX 2013 A pipeline is a sequence of one or more commands ...
-1
votes
1answer
41 views

Understanding operators using sed

Trying to understand and break down this command. echo -e '1234\n4567' | sed 's/^\(..\)\(..\)$/\1:\2/' Being a novice with shell and sed I'm at a loss where to start in breaking down various ...
0
votes
3answers
76 views

How to understand the definition of a simple command?

From POSIX 2013: A ‘‘simple command’’ is a sequence of optional variable assignments and redirections, in any sequence, optionally followed by words and redirections, terminated by a control ...
0
votes
0answers
32 views

bash script and multiple gnuplot

I have following 16 files PO01_energy PO02_energy PO03_energy ... PO16_energy I wish to plot a 16 graphs with gnuplot. So, I write a code like for i in 01 02 03 04 05 06 07 08 09 10 11 12 13 14 ...
1
vote
2answers
62 views

Why some commands don't load user environment when executed with ssh? (while other do)

On a target machine (OS X El Capitan) I have brew in /usr/local/bin. When I try to get brew's path I get no result: # ssh vagrant@127.0.0.1 -p 2222 which brew # Troubleshooting: brew is in ...
-1
votes
1answer
33 views

What characters are allowed in an alias?

I am confused as which are the allowed characters to be used in alias? With a function defined as f(){ echo "yes"; } Is it possible to create an alias like: alias fé='f' ### works alias ...
3
votes
2answers
49 views

How to make a function available to the command `parallel` (GNU)?

In Bash, let's consider a function that does nothing but echo the argument followed by "is an integer". f () { num="${!1}"; echo $num is an integer; } number=12 f number # 12 is an integer I would ...
-1
votes
1answer
40 views

How to check if a directory exists I don't know the exact name of it with a bash script

I need to check if a directory already exists, in this case the one with a number suffix, and I won't know the exact number. Example directories to search: /usr/ names names.backup names.20160316 ...
0
votes
1answer
28 views

vi is frozen after search on arch linux

I'm on Arch Linux live USB. I'm using vi to open an 18kb text file containing a single line of json. I did a search with / and hit a block partway through the file represented by an @ symbol. Then, ...
3
votes
1answer
243 views

What characters are required to be escaped in command line arguments?

In Bash, when specifying command line arguments to a command, what characters are required to be escaped? Are they limited to the metacharacters of Bash: space, tab, ‘|’, ‘&’, ‘;’, ‘(’, ‘)’, ...
1
vote
2answers
213 views

What is the difference between using bash and sh to run a script?

Does bash and sh execute a script differently? I executed a shell script with both bash and sh, and got the same output. So what is the difference? Also, when you just run ./executable, does it use ...
1
vote
3answers
62 views

Run a shell script via a symbolic link from the directory containing the script itself

My desire is not to change directory then execute. I use a jar file and need to execute that. So I made a very basic shell script to do that. #!/bin/sh java -jar TreeForm.jar Then, I saved it as ...
0
votes
1answer
53 views

for loop problem, detect file with size and copy regardless of name

The situation: I want to copy all odt files with size greater than 0 from one folder into another. Filenames will contain the following characters: + % & [ ( and spaces. Here is my attempt: ...
1
vote
2answers
71 views

How to understand this POSIX description about `(`, `)` and `test`?

From POSIX 2013: The XSI extensions specifying the -a and -o binary primaries and the '(' and ')' operators have been marked obsolescent. (Many expressions using them are ambiguously defined by ...
0
votes
0answers
35 views

unable to adjust screen brightness in kali linux ASUS ROG

With a great difficulty i managed to install kali-linux on to my ASUS-ROG but now i am not able to adjust brightness of my computer. My brightness keys and fn key both are working fine. I checked them ...
12
votes
1answer
548 views

never use the `-a` or `-o` operator with `[`

Stéphane Chazelas wrote: a few rules like always quote variables never use the -a or -o operator (use several [ commands and the && and || shell operators) Make [ ...
3
votes
2answers
87 views

What does the comma operator do in Bash arithmetic?

In Bash Manual, sec 6.5 Shell Arithmetic expr1 , expr2 comma What does the comma operator do? Are expr1 and expr2 arithmetic expressions?
0
votes
1answer
30 views

Redirection Error in Function [closed]

I'm trying to figure out why the code below doesn't work, and gives me an error Bad file descriptor. It is sort of a follow-up to this question as applies to the script I'm currently working on. ...
3
votes
2answers
81 views

Returning a String and Understanding Redirection and Output

I'm trying to figure out how redirects could be used to selectively output a string from a bash function which needs to print multiple lines to the terminal. I found an answer on this question at ...
0
votes
0answers
26 views

How can I see Bash shell perform lexical, syntax analysis, expansions, and redirections in action?

When I try to read the grammar of shell language in POSIX 2013, I often feel difficult to understand. Can I examine how Bash shell perform lexical, syntax analysis, expansions, and/or redirections on ...
1
vote
2answers
47 views

Difference between 1> and >

Is there any difference between (# comments taken from documentation) command > filename # Docs: Redirect stdout to a file. and command 1> filename # Docs: Redirect stdout to file ...
1
vote
1answer
30 views

Difference in conditions /test

Lets say i have to test if file contains a string "mail" , what is the difference between if grep -q "mail" "file"; then ... if [ $( grep -l "mail" "file") ]; then ... [ grep -l "mail" "file" ] ...
0
votes
2answers
64 views

If filename has more than n characters, delete the last ones

I'm kinda new with the unix shell, and I don't seem to find the answer of my problem : I have a folder containing multiple files : a correct filename contains exactly 13 characters (numbers + letters ...
0
votes
2answers
44 views

Syntax for rm command. Worried about using the -r option

I am trying to create a routine to manage the backup files I am creating, so that older folders will be deleted automatically in the process. Here’s what I've got: #!/bin/sh day=$(date +%m%d%y) ...
0
votes
1answer
46 views

How to grep response to figure out how many calls got timed out?

I have a curl command which is calling one of our service so if my service timesout, it returns JSON response like below: [{"results":{"response":null},"error":{"errorCode":1001,"message":"Service ...
0
votes
2answers
34 views

What is the difference between token identifier WORD and NAME?

In POSIX 7, the shell grammar (Section 2.10 in XCU) mentions several token identifiers. I am confused about two: WORD and NAME. What are their differences? For example, is a command's option WORD ...
3
votes
3answers
54 views

How to understand the order between expansions?

From POSIX 7: The order of word expansion shall be as follows: Tilde expansion (see Section 2.6.1), parameter expansion (see Section 2.6.2), command substitution (see Section ...
3
votes
1answer
54 views

How can I see the size of a partition's unallocated size on the command line after shrinking a partition with resize2fs?

I want to shrink my /dev/sda2 partition from 463.37GB to 400GB to make room for a new partition. So I did e2fsck -f /dev/sda2 followed by resize2fs /dev/sda2 400G. As per man resize2fs, the ...
1
vote
2answers
45 views

Does an external command which takes a command as its argument has restriction on the argument?

For an external command which takes a command as its argument, must the argument be an external command, not a shell's builtin command? I ask this question, based on the following two examples the ...
7
votes
1answer
578 views

What does `\time`, `t\ime` and `\cd` actually do? (fun with backslashes in shells)

While discussing over the differences between /usr/bin/time and the shell (bash and zsh) built-in time, someone mentioned that one can use \time as a shorthand to get /usr/bin/time. First it seemed ...