Tagged Questions

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
votes
0answers
15 views

Empty termina window - ZSH does not start? Can't use terminal

I have a chromebook pixel running Manjaro. Up until about 10 minutes ago, this machine was running great. I'd been using the terminal emulator (terminator) all day, when I tried opening a new shell ...
2
votes
2answers
35 views

Global Shell Variables?

As a system administrator with root access on a unix machine, is it possible to provide default shell variables to all users of a system? That is, as an individual unix user, I can define ...
1
vote
1answer
41 views

“Pipe” command to new bash shell?

I want to add my private key to the ssh-agent and I'm following these instructions. According to this the command ssh-agent bash spawns a ssh-agent bash and I can add my key afterwards using ...
1
vote
2answers
24 views

How to convert time from local timezone into Sydney timezone using korn shell?

I need to convert time from localtimezone (CET/CEST) to Sydney timezone (AEDT/AEST). I tried something like this: export date=$(date "+%Y-%m-%d %H:%M:%S AEDT") date "+%Y-%m-%d %H:%M:%S %Z" -d "$date" ...
0
votes
1answer
31 views

Unix shell script for server alerts

Below is my shell script which is written in another x to find the health of server y. ( I have not written in server y because there is no functionality of getting mails) #!/bin/bash ...
0
votes
0answers
51 views

Why isn't this `expr … | bc -l` command working?

I'm noticing an error: bash: syntax error near unexpected token `-105.5*7+50*3' When executing the below script/expression: expr (-105.5*7+50*3)/20 + (19^2)/7 | bc -l Is there any other way ...
3
votes
7answers
156 views

get parts of string using shell script

I have one string as /ip/192.168.0.1/port/8080/ I want to get two separate variables which will contain port and IP like. 192.168.0.1 and 8080 as I know /ip/ and /port/ will be there always I ...
1
vote
1answer
23 views

Installing packages on multiple Centos machines

I have to install standard package like java 1.7 in 40 of my lab machines which are connected over a LAN. I know I can simply write a shell script to install something in user space of each system, ...
4
votes
3answers
61 views

Arithmetic operations with expr and variables

Why won't this statement work? total=`expr $mPercent / 100 "*" .482 + $fPercent / 100 "*" .518` mPercent is a number as a result of an awk statement, as well as fPercent. I also get "expr: ...
0
votes
1answer
43 views

How can a script ask me questions?

I am using this script to analyse data: #!/bin/bash in=/autofs/cluster/transcend/mega/scripts/ insub=/autofs/cluster/transcend/mega/dtn/20141015/123 out=/autofs/cluster/transcend/mega/scripts/1256 ...
2
votes
5answers
74 views

List files with line count and date

I want to be able to list files showing the number of lines the each file has and the date. I can happily get the line count using wc -l *. Not a problem. I can get the date using ls -l. Is there a ...
1
vote
2answers
40 views

Combination of echo, pipe and cat

I have a file name called temp.csv in my script one of the intermediate step is echo "some info" > final.csv | cat temp.csv >> final.csv at times the file final.csv is created without ...
13
votes
4answers
2k views

What does echo $-1 display?

What does the output of echo $-1, echo $-2, echo $-3.. mean? On one of my Linux boxes, it shows me: echo $-1 imsBEl1 echo $-2 imsBEl2 And on another Linux box, it shows: echo $-1 himBH1 echo $-2 ...
-1
votes
0answers
43 views

How to write a code which would output combination of two other files? [on hold]

I have two files. Using these two files as sources, I need to generate an output file. File1 will contain resistors connected to nets (Syntax: R1 Terminal1 Terminal2): See below R1 7n 1n R2 8n 1n ...
1
vote
1answer
24 views

Jenkins does not use system's locales

I got a interesting behavior in Jenkins. Jenkins' shell does not use my systems locales. Jenkins runs as user jenkins on my system. Logged in as jenkins via SSH: locale displayed: ...
5
votes
2answers
378 views

How to treat strings with spaces as a whole in bash? [duplicate]

I'd like to build an error handler which will make an empty file marked with the error_occur time. The core idea is to use the result of date command as a parameter. I did: time_stamp=$(date) touch ...
25
votes
1answer
1k views

Why can Shell builtins not be run with capital letters but other commands can?

Why is this? When I do this CD ~/Desktop It doesn't take me to the Desktop. But this: echo "foo bar" | GREP bar gives me: bar
4
votes
3answers
203 views

How do I find a file with a name which depends on the current date (and a random component)?

I have to check a particular path every day and find the file with a name of the form: StaticData_Sets_yyyymmdd-232550.txt The date in the name after the string StaticData_Sets_ is updated every ...
0
votes
1answer
44 views

Why does “redirect to a file” is executed as user, even with sudo? [duplicate]

I often encouter this problem and it really bugs me on why it is so. So let's take this example into account : [me@localhost:~]$ sudo command > /some/file.log As far as I know, this will not ...
2
votes
5answers
196 views

Why do newline characters get lost when using command substitution?

I have a text file named links.txt which looks like this link1 link2 link3 I want to loop through this file line by line and perform an operation on every line. I know I can do this using while ...
-5
votes
1answer
58 views

Extract multiple lines from text file [on hold]

Source : ! hostname RTR-1 ! boot-start-marker boot-end-marker ! logging buffered 64000 informational no logging console ! interface FastEthernet0/0 description LAN ip address 172.16.29.250 ...
1
vote
1answer
53 views

Why is the result of this for and while loop different? [duplicate]

I have a for loop: for host in $(cat ./hosts) do echo -e "$host" ssh -o "StrictHostKeyChecking no" $host "uptime" 2>/dev/null echo -e "\n" done and a while loop which is supposed to the ...
25
votes
2answers
2k views

How does `cat <> file` work?

cat < file prints the contents of file to stdout. cat > file reads stdin until Ctrl+D is detected and the input text is written to file. cat <> file, at least in my version of Bash, ...
0
votes
1answer
49 views

grep: input file 'X' is also the output

I use ubuntu 14.4, and attempt to redirect the output of grep command to a file, but I keep getting this error: grep: input file 'X' is also the output I've searched for this issue and just found ...
-1
votes
1answer
17 views

How do I use export setu command [closed]

What is the difference between export and export setu command? I have searched online these command (export setu) but it's not found.
4
votes
1answer
41 views

Why does BASH process substitution not work with some commands?

On occasion process substitution will not work as expected. Here is an example: Input: gcc <(echo 'int main(){return 0;}') Output: /dev/fd/63: file not recognized: Illegal seek collect2: ...
-2
votes
0answers
24 views

Need Script to Find Duplicate PID in a process [closed]

I need a Shell script to find the duplicate pids in the process. Please advise me Thanks, Srikanth.V
1
vote
0answers
16 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 ...
46
votes
2answers
2k 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
31 views

Will a shell script execute in Solaris? if not, which is the fastest way to make it compatible

I have written a shell script with #!/bin/sh shebang. I've heard that it won't work alongside with Solaris. And that I have to write a korn shell script. But in one of the threads an individual ...
-1
votes
1answer
77 views

How to insert the entry into the newline?

I have the following entry in a tab delimited file test1.txt key1 10|15 20 30 11|xx 21 31 key2 527|240 269 0 0 0 2462 546 281 0 0 Is there any way I can transform this file into the below format? I ...
1
vote
2answers
50 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
278 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
24 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
260 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
80 views

How I can modify a sh command? [closed]

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
28 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
40 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
37 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
17 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
35 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
28 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
25 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
44 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
50 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
173 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 ...
10
votes
4answers
437 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 ...
2
votes
1answer
88 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 ...