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)

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
784 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
37 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 ...
2
votes
4answers
167 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
66 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
36 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
183 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
166 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
89 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
34 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
34 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
9 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
57 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
34 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 ...
0
votes
0answers
19 views

IPC or command line? [migrated]

I'm creating a nodejs program that need to use some unix command. I have two choices either execute them using exec('command ...') which just execute the command with the given arguments. Or through ...
2
votes
1answer
40 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
52 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 ...
1
vote
4answers
94 views

Set, backup and restore colors in the terminal

I use this program to display all color available in the terminal. That waht I get: This program doesn't show me colors below 100. Why? Is there a way to display them. Is the are way to change ...
1
vote
1answer
21 views

CD with redirect to logger does not work

On Linux, the following cd works fine so cds into tmp: / # cd /tmp tmp # But this does not work (stays at root, nothing appears in /var/log/messages). Why not? / # cd /tmp 2>&1 | ...
1
vote
1answer
44 views

error ./c.sh: line 24: [: too many arguments in shell program

I am trying to make a shell script to print the amount of time user was logged into the system but I encountered a too many arguments error. I tried many methods from the internet but none worked. ...
0
votes
0answers
40 views

What does the double star/asterisk wildcard expand to? [duplicate]

For example, Where are your test specs located? (./test/specs/**/*.js) Will that descend in all subdirectories under ./test/specs/, recursively? What authoritative source discusses this ...
1
vote
1answer
60 views

XZ - Cannot allocate memory

If i run this command: XZ_OPT=-9 tar --xz -cvf files/compressed/xz/archive.tar.xz -C files/original/ . Get this message: xz: (stdin): Cannot allocate memory tar: ...
0
votes
3answers
323 views

The performance difference between a command that does the same thing

What is the difference? It is performed in the same? tar -czf files/compressed/gzip/archive.tar.gz -C files/original . tar -c -C files/original . | gzip -1 > files/compressed/gzip/archive.tar.gz ...
0
votes
1answer
28 views

Set LZMA compression level via tar [duplicate]

How can I set the compression level for this command? tar --lzma -cf files/compressed/lzma/archive.lzma -C files/original/ . With --bzip I just use: BZIP2=-9 tar --bzip2 -cf ...
0
votes
1answer
60 views

How to create a new line?

In the below command I am sending the mail . in the mail the meter id is being sent if [ -s "$TMP_RPT_FILE" || -s "$TMP_RPT_FILE1" ] then if [ -s "$TMP_RPT_FILE" ] then ...
1
vote
1answer
21 views

Arrange program windows out of bash script?

I'm writing a shell script to automatically launch my work environment. It would be pretty nice to arrange the program windows automatically (for example vim opens at the left on desktop, and browser ...
6
votes
4answers
594 views

How to print the name of missing files in a folder?

I have 2000+ files in a folder, but there are few files missing from the folder. Name of the files are like GLDAS_NOAH025SUBP_3H.A2003001.0000.001.2015210044609.pss.grb ...
0
votes
1answer
43 views

How to copy files to the timestamp generated directory?

Hello I am trying to copy all files from Documents directory to the backup directory that has a timestamp. So I have created a directory called bk$( the time stamp of the directory) and I am trying to ...
1
vote
1answer
41 views

Get value of environment variable in for loop

I have several environment variable pam_branch app_branch worker_branch I use an array to define different projects and I want to get the values of these env var by rebuilding them in a for loop ...
1
vote
1answer
95 views

Execute sh with parameters in bash

Hello I am newbie in bash and I am coding a daemon to execute a service. The syntax is ./ctlscript.sh start. When I execute service openproject start it should run this command, but it runs ...
1
vote
2answers
154 views

Get a refreshing list of running specific processes

I want to monitor running python processes with VSZ, RSS %MEM, %CPU etc. One of my priorities is a list refreshing every X seconds. I managed to come to the point of obtaining a refreshing list of ...
2
votes
4answers
137 views

Is it possible, with `sed` or otherwise, to apply a regex transform to an input stream that may not contain newlines?

I have a shell pipeline that contains a sed expression: source | sed -e 's:xxxxx:yyyyy:g' | sink It works but it has a latent flaw because sed works on whole lines. This means that the sink will ...
1
vote
2answers
38 views

Escaping double quotes in string

I have a string message which contains data in double quotes. I need to put \ in front of every double quote how can u do it in shell ? I used Perl and it works fine, but I'm looking for sh command: ...
5
votes
1answer
75 views

Variables outside of while loop

I am trying to echo the variables $f1, $f2, etcetera, outside of the while loop shown below. From what I understand, the scope of the variable is not correct. Therefore I tried a few of the ...
0
votes
1answer
13 views

Convert Asyncronus reset into syncronus reset in verilog

I have multiple Verilog RTL files in which we have use asynchronous reset. But I want to convert asyncronus reset to synchronous reset. Before: always @ (posedge clock or negedge reset) After: ...
5
votes
2answers
181 views

How to send all output to `logger` in POSIX shell?

I'd like to log standard output and standard error separately in .xprofile using logger. In Bash I think that would look something like this: exec 1> >(logger --priority user.notice --tag ...
2
votes
3answers
84 views

Modify multiple files in different folders with one command?

I have a file abc.txt in the folder /etc/zyz/ and also in a few sub folders /etc/zyz-1/ /etc/zyz-2/ How can I modify all of those files with a echo command for example (all named abc.txt) in every ...
1
vote
1answer
30 views

Filesize in for loop

I am trying to get the filesize of each file in a folder by using stat in a for loop. I know why the following is going wrong, but I don't have enough knowledge yet on how to fix this. #!/bin/bash ...
0
votes
1answer
53 views

Why is my CD command not working on a home-built shell? [duplicate]

I have written a very basic shell in C. It reads the input, then runs it using system(lineCopy); (lineCopy being a copy of the input). All commands will run fine in it, other than cd. When I try to cd ...
1
vote
2answers
38 views

Piping contents of multiple files between programs while keeping contents separate

I would like to read in a number of files and pipe their output to subsequent programs while still maintaining them as individual pipelines of data. program1 *.txt | program2 | program3 folder I ...
0
votes
2answers
60 views

Live monitoring of background jobs

I executed a command like this: nohup some_command &. Now this command is in the background. I can see it with the command jobs. Example output: [1]+ Running nohup some_command ...
1
vote
1answer
59 views

How to echo makefile variable through Make's $(shell …)

I have a GNU makefile. The makefile has a few tests (around line 65 from the linked file): UNAME = uname MACHINE ?= $(shell $(UNAME) -m) SYSTEM ?= $(shell $(UNAME) -s) IS_X86 = $(shell echo ...