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)

1
vote
2answers
48 views

How to subtract lines, in reverse, only if greater than previous line

I am working on a shell script that will read the lines of a file, in reverse. I need it to subtract the previous line from the latter, but only if the latter is larger. If it's smaller, then I just ...
0
votes
3answers
55 views

regex in `/bin/sh` shell

I would like to remove all files ending with a given set of extensions in a particular directory in a /bin/sh shell. With a /bin/bash I can do it with regex like this : rm path/(*.pdf|*.png) but ...
5
votes
2answers
43 views

posix placement of stdin redirection (<in cmd vs cmd <in)

I always write stdin redirection after the command, because for me it's more natural to have first the command and then the redirections (if any): some-command < input-file > output-file For ...
2
votes
0answers
14 views

restrict private apt repository with rssh - why does apt-get try /bin/sh?

I am trying to set up a private repository via ssh. My sources.list.d/ contains the entry deb ssh://user@host:/repo ./ user is a certificate only account on host. apt-get update works fine. ...
0
votes
4answers
39 views

Clearing the content of files by size

Considering if I list files in a directory: drwx--x--x 43 root wheel 4.0K Aug 18 12:52 .. -rw------- 1 root root 268K Aug 18 04:31 build_locale_databases_log -rw------- 1 root root 5.2M Aug 18 ...
0
votes
2answers
25 views

Putting a single quote in a filename [duplicate]

We can a make a directory named $"dollars"&<>\dogs if we surround it with single quotes like the following mkdir '$"dollars"&<>\dogs' However, what if I want to include a ...
4
votes
2answers
47 views

Capturing output/redirection of commands chained by &&

I have a series of commands a,b,c which I am chaining together with &&: a && b && c. I want to catch the output of all the commands to both stdout and stderr. a && b ...
4
votes
4answers
146 views

Null and escape characters

I know that a filename in Linux has no restriction whatsoever excpet for two characters '/' and '\0'. I know that '/' is prohibited because it is a directory separator but is there any other reason ? ...
1
vote
0answers
18 views

Write shrunken .img file to device file

I have a backup image of a device file /dev/sda3 that I created using: dd if=/dev/sda3 of=~/sda3.img. The image is very large, so I have re-sized it to remove empty space. My question is can I ...
0
votes
1answer
30 views

Run shell scripts with -x for debugging system v boot

I need to debug the userspace part of the boot process and would like to run all the scripts with sh -x by default so I can observe what’s happening during boot. It's an embedded system that's using ...
2
votes
2answers
98 views

Find differences in file and sorting file by key

So I have two language files, english and french. They are in this format: key=translation An example in English would be: ui.title=My Title And in French: ui.title=Mon Titre So I need a ...
0
votes
0answers
23 views

Create and Write .properties file

I need to write a shell script to create and write a file with .properties extension, that contains 3 values, where the first 2 values are user-defined and constant, the 3rd value will be the filename ...
3
votes
2answers
57 views

Convert a value into a “Binary Number” in a shell script

I know of bc: $> var="304" $> echo "obase=2; $var" | bc 100110000 Could it be done in shell (no external call)? This question: Binary to hexadecimal and decimal in a shell script Asks how to ...
6
votes
3answers
284 views

Print random lines respecting the order of the source file

I have a large text file (~500K lines) with short sentences (couple of words long). Additionally, there is some XML markup in most of the lines. Finally, the text file has been sorted before the ...
1
vote
2answers
49 views

Escaping a linux command

I'm trying to run a command from a script I wrote that basically replaces a string in file vzctl exec VZID sed -i 's/\/>/address="$IP\/255.255.255.0"\/\>/' "file.xml" The problem is the ...
0
votes
2answers
44 views

Installation of latest version R for linux

First I typed sudo gedit /etc/apt/sources.list after that I got one sources list then I typed deb http://cran.rstudio.com/bin/linux/debian wheezy-cran3/ then I get the error like this No ...
-1
votes
1answer
29 views

sed throwing sed: -e expression #(number), char (number): unknown command: `(letter)'

I wrote a shell script which reads some files and copy all the data from these files to other consolidated file. This happens multiple times and previously copied data will not be copied again. For ...
0
votes
2answers
48 views

Must I add “>&2” in the end of echo command?

For example #!/bin/bash INT=-5 if [[ "$INT" =~ ^-?[0-9]+$ ]]; then echo "INT is an integer." else echo "INT is not an integer." >&2 exit 1 fi When I delete ">&2". There is ...
2
votes
3answers
48 views

login shell (bash) - how to we invoke a login shell

I know what is a login shell and the difference between a login shell and a non-login shell. But what puzzles me is how it is invoked. It is said that a login shell is invoked with a - as argument ...
0
votes
1answer
30 views

How to list only the file names of the same type in the directory?

I got a two group of files in the same directory *fmb and *fmx. I'm a rookie using Linux Terminal, and I want to learn how to print only the file name of fmb files, file1.fmb, file2.fmb, file3.fmb ...
1
vote
1answer
42 views

Why are arguments of a command altered when viewed by ps?

When I run my favorite app, why the arguments look different when viewed by ps? $ redshift -l 12.94:43.75 2>/dev/null 1>&2 & [1] 8637 $ ps -o cmd= -C redshift redshift -l 12.94 43.75 ...
2
votes
1answer
43 views

Do not wait until the return for Shell redirection

I would like to redirect the output of a script (Python or any other kind) to a file. Easy to do with > or >>. But with these two the output seems to be written in the file only once the script ...
0
votes
0answers
24 views

Unable to specify a paper tray with bash script

So we use a bash script that sends control codes before printing to set some things on the printer. At the end of the script it calls a standard lp command. I add the option to print to a specific ...
2
votes
1answer
62 views

SSH into a remote shell, execute a 'source' command, and stay in the remote shell

I've got a script, named s, on a remote server that activates a virtual environment like this: source venv/bin/activate When SSH-ed into the server, I'm able to activate the environment by . s ...
0
votes
1answer
23 views

How shell get control of the terminal after wait()?

We know shell forks(),assigns it to a different process group and make it the foreground process group such that cntrl-c and cntrl-z will go to the child process group and the parent waits on it. ...
3
votes
0answers
21 views

cursor and combining diacritics in shell

I frequently deal with combining diacritics, especially the combining acute accent (U0301, or \xcc\x81). I have a keyboard set up to insert this character, and that works fine in the shell. $ echo а́ ...
0
votes
1answer
35 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' | ...
2
votes
1answer
65 views

Bash - shell vs environment variable [duplicate]

I want to clarify a confusion I am having in shell variable vs environment variable. I did the following test, where I have a shell variable abc and export it to an environment variable. $ $ ...
1
vote
1answer
45 views

choose between one of two programs in bash script

I have a (bash) script I would like to run on two different computers, one is OpenBSD with the program sha256, the other is Ubuntu with sha256sum. What is the best/standard practice to allow the ...
1
vote
1answer
35 views

search and increase the values between the second tilde symbol and the 3rd tilde symbol in each line of a txt file

I was wondering is there any way to search and increase the values between the 2nd tilde symbol and the 3rd tilde symbol in each line of a txt file. Maybe vi can do this? For example, i have a ...
2
votes
2answers
53 views

What other special characters are there?

For filenames, I know that you have to use either a double quotes or a backslash to include a space in your file name. Like mkdir "I like coffee" is the same as mkdir I\ like\ coffee Now when you ...
1
vote
1answer
33 views

How do you sudo with xonsh?

I get the error xonsh: subprocess mode: permission denied: sudo.
0
votes
2answers
58 views

File exists but mv errors out with: “mv: cannot stat ‘file.tar.gz’: No such file or directory”

I am creating a script in Centos 7 to move the latest file within a directory to another directory. The original directory that I'm copying from contains a valid file, however when I try to move or ...
0
votes
0answers
36 views

Concatenating two strings cuts string

I extract two numerical strings from a textfile and and want to combine them to create a new string. The new string will be a filename. This is the textfile dates.dat: 378464,2015-01-31 ...
0
votes
1answer
37 views

.sh script error issues

I have a sh script with which I connect to postgres DB and execute a psql command. The script is as shown below: /opt/postgres/9.2/bin/psql pcwh -U pcwhuser << EOF \i ...
1
vote
2answers
56 views

Odd syntax for ssh and bash to run command

I'm pretty new to shell/bash scripting and I'm writing a script on OSX to automate some rather tedious efforts. I'm trying to run a portion of my script on a remote host using ssh. There's a common ...
2
votes
1answer
42 views

Bash do action as nobody and nogroup?

I have a log file that was created by nobody:nogroup, which is activity being logged to, I wanted to emulate adding a message to that log file. My first though was to: $ sudo su nobody This account ...
3
votes
3answers
116 views

Print man pages with fixed width

With the example command man apropos > outputfile a text file is generated which contains the formatted man page of apropos (with some little differences with respect to man apropos directly ...
0
votes
0answers
29 views

Writing a basic shell script [duplicate]

I'm using a cluster and I want to write a start up script to run the commands I have to run at the beginning of every session. My script looks like this #!/bin/sh module add apps/COPASI module add ...
0
votes
2answers
62 views

Display CPU cores usage in percentage without using top

I am using java to run a command on linux. Since top is an interactive command and need to press 1 to get the info of all the cpu(s) so I cannot use that. So I am using the following command to get ...
1
vote
1answer
57 views

How to execute a for loop in bash as a string

I need to execute a loop as a string. This: bash -c "for l in $(/bin/ls /dir1); do /bin/ln -sf $l /dir2/; done" Gives an error: /bin/bash: -c: line 1: syntax error near unexpected token `file1' ...
4
votes
3answers
555 views

Behaviour of “|” pipe in linux with “>” output redirection

I am executing command ls > a.txt | sort > b.txt This command is doing the below things : executing ls sorting it creating a.txt and storing sorted output to a.txt creating b.txt , but its ...
2
votes
1answer
39 views

crontab versus manual running script

I wrote a script to check for wifi connection that has an "if then else" statement. If I run the script manually the "if" statement is 1, as it should, if the crontab runs it automatically the "if" is ...
0
votes
1answer
39 views

How to get a X line from file1 and Y line from file2 using shell command?

In file 1, 'Server restoration is complete now. It will be operational within few seconds. Please keep all the log file once the restoration is complete.' In file 2, 'Restoration was successfully ...
0
votes
2answers
16 views

Assigning output of a Dynamic Performance View (v$asm_diskgroup) to a variable in Shell Script

I am trying to assign the output of select name from v$asm_diskgroup; to a variable in Shell . The script is failing because of special character '$' in the table name . Note : While i ...
0
votes
2answers
54 views

To add line numbers in every line using shell command?

My file, PSS-A (Primary A) PSS-B (Primary B) PSS-C (Primary C) PSS-D (Primary D) PSS-E (Primary E) PSS-F (Primary F) PSS-G (Primary G) PSS-H (Primary H) PSS-I (Primary I) SPARE ...
1
vote
2answers
33 views

unable to login via tty{1-6} as a normal user

Unable to login via tty{1-6} as a normal user. Can only login as root. When logged in with normal user it displays the greeting message from /etc/motd and logs out immediately. What could be the ...
-1
votes
2answers
100 views

How to remove a column or multiple columns from file using shell command?

My file, ARCHIVE B1_NAME B2_NAME B3_NAME ELEMENT INFO_NAM WERT PROCID -------- -------- -------- -------- -------- -------- ---- ------ ...
0
votes
2answers
31 views

Copy file,create duplicates in different directory with predefined list of filenames

I have a file rock.mpg in the folder directory /folder1/folder2. I need to create multiple (340) duplicate copies of this file in a different directory say /folder1/folder2/folder3 but with different ...
-1
votes
1answer
24 views

Assign regular expression as character for a variable

I am wondering is there is a way to assign a regular expression as a character in a string to a variable and not have the regular expression change my variable. For example: in my directory I am ...