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
34 views

How to handle space character in input from user

I have recently started working with Shell scripting. So, I am facing one issue that when i am taking filename as an input from user, then if I give spaces then it does not get handled with my code. ...
-2
votes
0answers
14 views

Will zip -r command on remote server be cancelled if I exit terminal? [duplicate]

I have done a lot of Googling, and cannot find an answer. I have made a "zip -r home" request on my server via my terminal. The home directory is over 30GB. I need to leave the office at some point ...
-1
votes
2answers
24 views

collect and create tab separated matrix

I have 6 text files (each corresponds to a specific sample) and each file looks like this: Gene_ID Gene_Name Strand Start End Length Coverage FPKM TPM ENSMUSG00000102735 Gm7369 + ...
0
votes
1answer
51 views

syntax error: invalid arithmetic operator (error token is “.c”)

I am trying to test if file "file1.c" is present in the current working directory, what am I doing wrong with my test command? I thought I understood this command, am I doing something wrong for the ...
3
votes
4answers
100 views

How to execute multiple commands remotely on few servers?

I am trying to automate these steps so that I don't need to do this on every machines manually. I need to install latest app server software (abc.tar.gz) on all the unix boxes. I need to do this in ...
4
votes
1answer
60 views

Automatically open text files in editor instead of attempting to run them?

When I accidentally type the name of a text file without some kind of editor command, and the text file is not a shell script, I get a "permission denied" error*, since the file is not executable, and ...
1
vote
2answers
47 views

how to kill job in background?

I know how to kill a job with kill %(number) but is it possible to kill a job as background job, the question is "kill tail as a background job?"
0
votes
2answers
24 views

BASH How to save the output of rm -vri to a var [duplicate]

How can I save the output of this command into a var and still remove the files? rm -vri files | wc -l
0
votes
2answers
29 views

/usr/bin/find invocation doesn't work when used with command substitution [duplicate]

In a script, I have: CMD='/usr/bin/find /etc -type f -exec /usr/bin/md5sum {} \; ' MD5=$("${CMD}") But the script gives the error: -bash: /usr/bin/find /etc -type f -exec /usr/bin/md5sum {} \; : ...
-3
votes
3answers
35 views

unable to scp a file with a space in name [duplicate]

Actually the problem is that on the image bellow.
3
votes
4answers
93 views

How do I extract a long listing field?

I want to extract the access day of a file in a shell script. I tried by writing the following script but it doesn't work. When I echo accessday, the output is "staff". file=$1 accessday=$(ls -lu ...
0
votes
3answers
66 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
82 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
166 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
66 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
40 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
55 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
41 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
76 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
63 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
52 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
214 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
67 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
553 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 ...