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
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
22 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
37 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
74 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
48 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
54 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
59 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
39 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
60 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
121 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
63 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
561 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
34 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
102 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 ...
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 ...
0
votes
0answers
21 views

To list only the file names in a present working directory using unix shell command [duplicate]

There are some links,directories and files in my path. I want to list only the file names eg. logfile1 redolog1 dumplog1 logfile2 lrwxrwxrwx spsy spec Jun 23 2343243 jpeg --> ~/home/s/jpegs ...
15
votes
3answers
789 views

Can I make a public directory under a private directory?

I have a personal folder /a/b on the server with permission 700. I don't want others to list the contents in /a/b. The owner of /a is root. Now I need to open the full authorities of directory /a/b/c ...
2
votes
0answers
30 views

Restrict a user from viewing other user's processes [duplicate]

Suppose there are two users : user1 & user2. Now we know that if I give top -u user1, I can see only the process respective to user1. But if I do top -u user2, I can see all the process running ...
-1
votes
1answer
38 views

How can I delay the evaluation of variables (lazy evaluation)?

For example, I create 32768 directories named 0,1,2,...32767. I want to randomly choose one as the path every time I run a command. So I change $PATH to $PATH:/blabla/$RANDOM, but it won't work ...
3
votes
5answers
192 views

How do I *reliably* and *simply* get the current shell interpreter name?

I'm looking for a simple and reliable way to get the name of the current shell from inside a script or a sourced file (not from the command line). I would have expected to just do $(basename ...
-1
votes
2answers
68 views

How do I take a prompt response and send it to a text file?

I'm new to shell scripting and I need help I want to ask the user what is their ORACLE_SID, ORACLE_HOME, and then send the output in a file. I want to create a param file that has ORACLE_HOME= ...
2
votes
3answers
37 views

Who forks the processes of piped commands in the shell?

Suppose this command in the shell : ls|less Now we know that ls and less are run as two different processes. We know that the shell forks and creates a child process which load the ls program using ...
3
votes
3answers
216 views

Checking environment variables' value in Makefile

I have a Makefile target, in which I have to check the value of an environment variable. But, I don't get the exact syntax of it. Tried hard, but can't find it. Any help is appreciated. Environment ...
4
votes
1answer
167 views

Any problem assigning one variable to another in shell without using quotes? [duplicate]

This question is about assigning the entire contents of one variable to another variable. Variable is not being used (sent to echo, etc.) No parameter expansion is being done during the assignment. ...
-1
votes
2answers
65 views

Executing script after error

I want to continue execution of shell script even after error in particular step, but it is getting terminated after error if [ condition ];then cmd else cmd1 return 4 fi cmd2 I ...
4
votes
1answer
48 views

Where to save temporary files for shell scripts

I have a script to toggle my screen backlight (mapped to a keyboard shortcut), and I want to save the brightness level so I can restore it when pressing the keyboard shortcut again. Is there a ...
2
votes
1answer
90 views

arithmetic syntax error in string compare

I have written a shell script which takes file name as parameter e.g user/test.txt. I want to make this file parameter optional if user does not wish to provide file name he/she can give as "None" ...
1
vote
1answer
45 views

Sending command to second shell

Let's say I have one command window open, and it's running some Java application, regularly outputting text. If I wanted to send a command to it, I could just type it in and press enter. But how ...
0
votes
0answers
7 views

How do I edit my directory colors in zsh so directories in a network share aren't so ugly? [duplicate]

The display colors of directories located on mounted network shares are horrid: Local directories look much nicer: As I understand it, these settings are set in these lines in .zshrc: eval ...
1
vote
1answer
35 views

Vi mode or emacs mode in the whole system

I use vi mode in zsh, tmux and my favorite text editor (vim obviously). I'm interested to have this behavior in the whole system. I know I can use plugins in firefox, thunderbird, etc. but if there is ...
0
votes
2answers
37 views

How to run to parallel gnome-terminal windows?

I'm looking to run two independent parallel gnome-terminal windows with some parameters, from 1 shell script. So far I've got this: #!/bin/sh gnome-terminal -e window1.sh & gnome-terminal -e ...
0
votes
0answers
10 views

Audio File Search, Count and Sort - OS X or Synology

There is a collection of audio files on a Synology NAS. Approximately 24,000 albums worth, that I need to analyse and report on. I will need to: Count total number of files Count types of files ...
1
vote
1answer
22 views

Backward and foreward search are inversed with vi mode in zsh

When I enter in vi mode with set -o vi, I enter in command mode, and I touch the key ? it produce a / and the inverse. Is it normal ? How to change this behavior?
4
votes
1answer
58 views

“$@” expansion for user defined variables

I'm trying to get a (bourne shell) variable to expand like "$@" so it produces multiple words with some having preserved spaces. I've tried defining the variable in many different ways but still can't ...
0
votes
0answers
26 views

Start a process from (noninteractive) shell script (cgi) and keep it running when script ends

I want a cgi script to start a process which stays alive after the cgi script exits. I tried: #!/bin/bash nohup process-to-keep-running & That works fine, if I run the script from an ...
1
vote
2answers
37 views

shell script for chmod file name but only on new files since last run of the script

i have a directory where new files are uploaded and receive numeric filename as they are uploaded. the file name is numbers that go up. i need to change permissions for the file but only on new files ...
2
votes
1answer
41 views

Format sar samples live with paste and awk

I'm combining live sar samples with paste and trying to format the output with awk live. It works as expected to format the output, but it doesn't do the formatting live on each sample and instead ...
1
vote
0answers
53 views

Recording shell output for interactive commands

While looking into a shell redirection problem, I found a couple of answers that pointed me to the script command. As I understand it, script just records in- and output of the terminal, and allows me ...