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)

-3
votes
0answers
10 views

Need Script to Find Duplicate PID in a process [on hold]

I need a Shell script to find the duplicate pids in the process. Please advise me Thanks, Srikanth.V
0
votes
0answers
9 views

does sudo always set process limits to the numbers from /etc/security/limits.d?

I have observed the following behavior: [ec2-user@ip-10-66-68-55 ~]$ uname -a Linux ip-10-66-68-55 3.4.103-76.114.amzn1.x86_64 #1 SMP Fri Sep 12 00:57:39 UTC 2014 x86_64 x86_64 x86_64 GNU/Linux ...
20
votes
2answers
681 views

Is >&- more efficient than >/dev/null?

Yesterday I read this SO comment which says that in the shell (at least bash) >&- "has the same result as" >/dev/null. That comment actually refers to the ABS guide as the source of its ...
1
vote
2answers
45 views

How to use sudo to delete the contents of a directory

I have a legitimate need to empty a directory to which my account does not have access (it is a cache directory used by an application, and is owned by the account that runs the application.) My ...
3
votes
2answers
258 views

grep on a variable

Lets say I have a variable line="This is where we select from a table." now I want to grep how many times does select occur in the sentence. grep -ci "select" $line I tried that, but it did not ...
0
votes
0answers
23 views

route -n gives output “route: fscanf”

If I boot my system and no interface has an IP address I get the above output. However if I give an interface an IP, even if I remove it again, this will disappear. Why does this happen? Is it that ...
4
votes
1answer
252 views

Why does “cat /tmp/out1 > /tmp/in2 &” appear as “bash” with the “ps” command?

Consider: mkfifo /tmp/out1 mkfifo /tmp/in2 cat /tmp/out1 > /tmp/in2 & When I run ps it appears as bash in the CMD section. Why?
0
votes
0answers
74 views

How I can modify a sh command? [on hold]

I need to modify the code for one of the sh commands. For example: Add a one line of code that prints your name when a command is executed by a user on the shell. I want editing of source code for ...
1
vote
1answer
24 views

How to check PIPESTATUS equivalent during PROMPT_COMMAND execution?

I have a custom $PROMPT_COMMAND in bash that logs the last executed command and its return code. I was using $? for the latter happily until I realized that for piped commands this was insufficient. I ...
0
votes
4answers
35 views

How to save in a variable the convert from decimal to binary without use an echo

I've been trying to save in a variable the value of the convert of a number from decimal to binary, like this: num1=10 echo "obase=2;$num1" | bc | tee -a register.txt but I don't want to show it ...
2
votes
2answers
35 views

saving the output of command line in a text file?

I am using the following command line to analyse data: unpackdcm -scr ${in} -targ ${out} This command is printing on the screen status and description about the progress in the job. In order to ...
1
vote
1answer
16 views

Print difference of column1 if column2 values are same

I have a file something like this: 19:32:19 4599544 19:32:22 4599544 19:33:07 4599545 19:33:11 4599545 19:33:58 4599546 19:34:01 4599546 1st column is ...
0
votes
1answer
33 views

Howto adapt this bash construct to a sh valid construct

On converting some bash scripts to a platform where only /bin/sh is available i'm stumble about this bash construct: #!/bin/sh RSTPD=/sbin/rstpd RSTPCTL=/sbin/rstpctl RSTP=0 ...
0
votes
0answers
24 views

Unix Shell script to delete all traces of itself after execution through crontab

My Question has 2 parts. Help with both parts is greatly appreciated. GIVEN INFO: - Lets assume there are 2 Folders, Folder A and Folder B. - Folder A contains many files. - Folder B contains the ...
0
votes
1answer
22 views

saving contents of echo output to variable in non-bash script

I'm used to doing something like this in my bash scripts to echo output to a variable: myvar=`echo $OSTYPE` echo "my os is of type: ${myvar}" On this current project however I'm using sh, which on ...
-2
votes
1answer
43 views

How do I automate this in a shell script?

I'm using the application PlexConnect on my home server (a headless OSX box) and I have to ssh in (from an iMac) and manually kill the Python process sometimes with the following: ssh 192.168.0.7 ...
2
votes
2answers
46 views

An alias for a command to kill stopped jobs

I wanted to add an alias to my .bashrc so that I could kill all stopped jobs with a command like kill_stopped. I am aware that kill `jobs -p` can be used to accomplish this but I'd rather have an ...
1
vote
1answer
47 views

command not found via shell script but works on terminal

In my .sh file I cannot invoke ant or mv or cp commands but the same commands executes on terminal.below is my script sample.sh file #! /bin/sh cp filename.so filename_org.so android update project ...
2
votes
2answers
171 views

Shell script written in a different shell than what my current shell

If the shell script is #!/bin/sh But the value of my $SHELL is ksh. Will it make a difference if I changed my ksh to sh, and then executed the script. ie. will a script have different behaviour ...
1
vote
1answer
22 views

several virtual profiles for the same user

Many times there are several "identities" which one user uses: for work, open-source, academia etc., all require different ssh keys, editor configurations, git configs etc. I was wondering if there ...
9
votes
4answers
418 views

Regular expression using \\ vs using \

Why does grep e\\.g\\. <<< "this is an e.g. wow" and grep e\.g\. <<< "this is an e.g. wow" do the same thing? If I add a third slash, it also has the same result. BUT, once I ...
-1
votes
0answers
35 views

Practical usage of pushd, popd, man, less, and cat in bash [closed]

So i am learning more advanced usages of bash/cmdline due to work teaching me some programming and im trying to wrap my head around some of the following bash cmd's and their purposes. I have been ...
2
votes
1answer
80 views

How to pipe a command output to multiple programs

I'm using FFmpeg and I have made a custom application which is a TCP server. I 'm using duplicate output in ffmpeg. What I want is, for each output I want to start my program to listen on a specific ...
5
votes
3answers
756 views

What does “if !” mean?

I came across a if/then statement like this: if ! foo ; then echo "blah" exit 1 fi What specifically does if ! mean? "If the result of foo is not true?" "If the exit code of foo ...
1
vote
3answers
90 views

How to enter foo-* folder without actually using wildcard or shell expansions?

Short story I'm looking for the command to enter first found foo-something directory like: cd foo-* but without using wildcard (or other special shell characters). Long story As part of the ...
2
votes
2answers
41 views

Optional arguments after or before the mandatory arguments?

I'm creating a shell script and I need it to take two mandatory arguments and one optional. How do I check that? In most scripts I've seen, the optional arguments are passed before the mandatory ones, ...
2
votes
2answers
46 views

Environment variable not expanded inside the command line argument

I have a file user-pid.out2 which has "usernumber" and "process id" as two columns. based on usernumber I want to find corresponding process id. the first two lines below does not show the output ...
-1
votes
1answer
51 views

Is it possible to run two commands at the same time in a shell script?

I know that on the command line I can use & to run a command in the background. But I'm wondering if I can do it in a script. I have a script like this: date_stamp=$(date +"%Y-%m-%d" ...
3
votes
2answers
77 views

How to use getopt in bash command line with only long options?

There is a getopt command in bash command line. getopt can used with short options (such as getopt -o axby "$@"), and can be used with both short and long options (such as getopt -o axby -l long-key ...
2
votes
2answers
191 views

Meaning of \ before environment variable

In ksh on an old Solaris box I used: export PS1="$PWD $" to set the prompt to the current directory. It works great until you cd elsewhere, then you see that it's not evaluating PWD each time. I ...
47
votes
2answers
3k views

Shebang starting with `//`?

I'm confused about following script (hello.go). //usr/bin/env go run $0 $@ ; exit package main import "fmt" func main() { fmt.Printf("hello, world\n") } It can execute. (on MacOS X 10.9.5) $ ...
5
votes
3answers
691 views

Why does “$ sudo echo 'yo' ” work even though echo is a shell built in function? [duplicate]

I understand that sudo cd /directory will return: sudo: cd: command not found because cd is a shell builtin and not a binary. But then, why does sudo echo 'this is a test' works fine? What ...
0
votes
1answer
56 views

How can I echo dollar signs?

For example, $PATH and $HOME When i type echo $PATH it returns my $PATH, but i want to echo the word $PATH and not what the actual variable stands for, echo "$PATH" doesn't work either. It might ...
1
vote
2answers
45 views

how to use http proxy in terminal

I have to use a http proxy to access Internet. Now I'm using firefox with the http proxy to access Internet. But on terminal, I can' access Internet. So are there ways to use http proxy on terminal ...
-1
votes
2answers
32 views

Matching multiple patterns with ls

I'd like to get a list of fail logs in the current directory for use in an outside script, the logs are determined with the pattern FAIL in the filename, so I've been using a FAIL* to feed my script ...
0
votes
1answer
71 views

How do I use vim on the command line to add text to the middle of a file?

I am trying to write a command along the lines of the following: vim -c "XXXXXX" myFile Instead of the "XXXXX" I want to supply some commands to vim to add some text to an arbitrary point in the ...
3
votes
1answer
17 views

Why does unbuffer command affect time command?

I noticed something odd when using the unbuffer command with time command. Here I just want to see how long takes to find a certain file in my system: time find . -name unixstuff output is : ...
8
votes
2answers
183 views

Precedence of && vs & in bash and zsh

Answering this question I discovered a very funny (and subtle) difference between behavior in bash and zsh: In bash: romano@RRyS:~$ pwd /home/romano romano@RRyS:~$ alias x="cd /bin && ...
1
vote
1answer
33 views

No prompt after logging in

After entering my username and password when trying to log in, I am not getting the command prompt. This is what my screen looks like: pal login: root Password: Last login: Wed Oct 14 15:42:19 on ...
2
votes
4answers
162 views

How to read certain lines after a find some text?

How i can read a certain number of lines after find some text? Eg.: Read next 2 lines after find "Unix" on: Test 1 Test 2 Test 3 Test 4 UNIX Test 5 Test 6 Test 7 Test 8 Test 9 Result can be: ...
7
votes
3answers
229 views

Empty a file without grep subsequently treating it like a binary file

Currently I have netcat piping output to tee which is writing to output.txt with nc -l -k -p 9100 | tee output.txt I want to monitor this output, so I'm watching it with tail -f | egrep -i 'regex' ...
0
votes
0answers
28 views

port forwarding using Netcat [closed]

I have used Netcat for accessing shell and files. But I could not find any tutorial or script for port forwarding using Netcat. I want to use port forwarding script in my android phone. Please guide ...
1
vote
2answers
63 views

Check that a bash script has exactly two arguments which are directories

I'm writing a bash script that compares two directories, but I'm not sure how to check conditions For example, if the user enters 1 arg instead of 2 (we need 2 since we're comparing two directories), ...
2
votes
2answers
28 views

Clear or disable aliases in zsh

I installed oh-my-zsh to make terminal use a bit easier. One thing that bugs me though is the prolific aliases added by it, like "ga", "gap", "gcmsg", "_", which are harder to remember than the ...
4
votes
4answers
275 views

extract every nth character from a string

I am trying to figure out a solution for this question. My approach to this problem so far is as below. Append all the characters together to make it a long string. After the above step, remove ...
1
vote
1answer
21 views

How to copy with wildcard in directory name?

I would like to copy the html directory inside a directory like cms_drupal_PROJ-1-2 to /var/www. The last digit in the working directory is dynamic so at any given time all I know is ...
0
votes
1answer
23 views

UNIX stdout redirection

I've written a script and I want to direct the console output to a file, so I use this command: ~/simplesim-3.0/sim-cache -cache:dl1 dl1:1:64:2048:f -cache:il1 il1:1:64:2048:f \ -cache:il2 dl2 ...
2
votes
4answers
185 views

Remove file with ` in name

At some point I created a file with: ` in it. How do I remove it? ls -la returns: -rw-rw-r-- 1 ec2-user ec2-user 0 Sep 25 23:01 `which
0
votes
3answers
82 views

Can dash replace bash as my default shell?

From what I read, dash can be made as a shell by using the command ~$ chsh shirish Password: Changing the login shell for shirish Enter the new value, or press ENTER for the default Login Shell ...
5
votes
2answers
682 views

Why doesn't 'sudo bash && cd desktop' cd in to the desktop folder? [duplicate]

I have a folder with chmod 000 permissions on it with a lot of different stuff in, the way I get in is a start bash in sudo by running sudo bash. Why can't I do &&? I want to cd into the ...