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)

2
votes
3answers
53 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
30 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
47 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
11 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: ...
4
votes
2answers
157 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
68 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
23 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
35 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
34 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
36 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
29 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 ...
0
votes
1answer
42 views

Which are (bash) shell special parameters?

I've found some special parameter with bash starting with $ sign. Example: When I was wandering for exit status I knew about $?, process ID by $$ etc. So, I am sharing this post to know Which are ...
0
votes
0answers
14 views

Why won't MOTD display output from a Python script it calls outside of /etc/update-motd.d/ unless it's in this directory?

The Situation We're running a headless Ubuntu 14.10 Server to fulfill various needs and tests. I was experimenting with changing the MOTD for SSH sessions via /etc/update-motd.d/ so as to display ...
-1
votes
2answers
95 views

Free or cheap shell (i.e., platform) to run a Linux C program with root privileges (raw socket)

I'm working on a Linux C program that needs root privileges (raw socket). I would like to run it on a host located in the US (I am in EU) to compare results. Is there any free (or cheap) shell ...
32
votes
3answers
2k views

Is there ever a good reason to run sudo su?

To launch a root shell on machines where the root account is disabled, you can run one of: sudo -i : run an interactive login shell (reads /root/.bashrc and /root/.profile) sudo -s : run a non-login ...
0
votes
1answer
49 views

Why the number is rounded over ssh? [duplicate]

localhost:~ $ df -k / | awk '{print $3/1024/1024/1024}' 0 0.00618061 localhost:~ $ ssh localhost "df -k / | awk '{print $3/1024/1024/1024}'" 01 01
1
vote
0answers
26 views

initramfs-tools syntax errors with Heirloom sh

My current system is: $ lsb_release -a No LSB modules are available. Distributor ID: Debian Description: Debian GNU/Linux 8.1 (jessie) Release: 8.1 Codename: jessie with kernel: $ uname -a ...
3
votes
2answers
121 views

Which shells don't support dollar-parenthesis expansion, and demand backticks?

The modern recommendation is to use: $(...) instead of the older: `...` mainly for readability and to avoid the need for escaping when nesting. Which shells do not support the $(...) form, and ...
2
votes
2answers
31 views

find closest matching folder

What is the best way to sort the results of $ find . -name scripts -type d by the occurrences of '\' and then choose the first result. I want to create an alias that would cd down to a common folder ...
0
votes
1answer
17 views

Run .zshrc when passing command via -c

I have a script that runs a command via zsh -c. However, when zsh runs, it doesn't appear to load ~/.zshrc. I understand a login shell flag exists, but even zsh -lc <command> doesn't seem to ...
2
votes
1answer
37 views

bash on command event (or shell)

Is there a way to capture all commands executed in a bash or even better in sh? I need a wrapper script that gets called everytime a command is executed. Like when I type cd /home/ I want my ...
2
votes
1answer
26 views

Restart bash from terminal without restarting the terminal application (mac)?

I've looked around and bit for an answer to this question but I don't seem to find it (which is weird). My question is, is there any simple way to restart the bash session from within the terminal on ...
7
votes
7answers
2k views

How can I make a script to count up by fives?

I was trying to make a very simple bash script to list all of the multiples of five between 375 and 3500 (375, 380, 385...). One thing that I tried and didn't work is: for i in {375..3500} do ...
1
vote
1answer
40 views

du reports directory size as much bigger than the sum of its contents

Running du -shc * in the top directory gives 110G for a particular folder, whereas running the same command inside that folder gives a total size of 11G. How is that possible? Platform Details: OS: ...
1
vote
4answers
53 views

Pipe output of one command to two others [duplicate]

I need to pipe the output of one command to two other commands. cat filename.txt | tail -n 1 cat filename.txt | wc -l Since the file is huge I want to avoid reading it twice. I checked tee command ...
2
votes
0answers
41 views

shell operation within makefile [on hold]

I have the following line in my makefile: var := $(sort $(foreach m,$(libs),$($(m)-objs))) which I change in a way it now use sort from shell: var := $(shell echo $(foreach ...
0
votes
1answer
49 views

Bash script strange behavior - script does not act as manual commands

So, this is strange. When I manually run commands it all works fine, but when I run a script with identical commands, I get strange error output. This is what I run: lxc list; for elem in ...
-1
votes
1answer
38 views

How to rename or delete an alias permanently from system?

I have created one alias in my system, printf "%s\n" "alias shh='sqlplus hfdora/hfdora@hfd2" >> ~/.kshrc Now, I want to change the alias name from shh2 to shh Also, how to delete other ...
2
votes
2answers
28 views

Call a script for another script, but don't exit the parent if the child calls exit

first.sh: #! /bin/ksh echo "prova" . ./second.sh echo "ho lanciato il secondo" . ./third.sh echo "ho lanciato il terzo" second.sh: echo "sono nel secondo script" dosomething1 exit $? If ...
0
votes
2answers
44 views

cut string on last delimiter

I have a filename like a.b.c.txt, I want this string to be splitted as string1=a.b.c string2=txt Basically I want to split filename and its extension.I used cut but it splits as a,b,c and txt. I ...
1
vote
2answers
46 views

Returning an variable from a function

I have the Linux script from bellow. I can get to return from the method decrypt nothing in order to unzip a file. The method decrypt sends a string with the name of a zip file. Please give some ...
-8
votes
1answer
57 views

replace the the first line of all .sh files in a folder

Create list of all .sh files in current folder. Check first line of each file in this list and if file starts with #!/bin/sh then replace that with #!/bin/bash. Only modify files that have #!/bin/sh, ...
0
votes
0answers
16 views

Adapt text lines to fixed length [duplicate]

With the shell command fmt -w 30 myfile it is possible to truncate the myfile lines so that their length is at most 30 characters. The result is however not a justified file: some lines will be ...
-5
votes
1answer
61 views

Find the number of files with sizes

Find the number of files with sizes > 100KB in /, /bin, /usr, /usr/bin and /usr/sbin directories and output them in a two column format with the name of the directory and the number of files.
0
votes
1answer
26 views

remove _ as prefix from the multiple files in a directory in Soalris [duplicate]

I have to remove _ which is as prefix for a file. I used: for i in _*.txt; do mv ${i} ${i/#_/''}; done but it does not change the names of the files which has space in between as _abc xyz-abc.txt ...
2
votes
1answer
77 views

What are the Linux shells that allow network traffic management (sending/receiving data to/from `/dev/tcp/host/port`) via redirectors?

Following this Bash tutorial, I have succeded in obtaining the code of a web page issuing simple commands by using this method: $ exec 3<>/dev/tcp/www.google.com/80 $ echo -e "GET / ...
2
votes
2answers
46 views

Seems like some basics are missing from ubuntu…or I haven't set them up?

I can't define a shell variable like so: $a = "hello" echo $a echo a $a a all lead to nothing. Also, this command doesn't work for me: $ echo "HELLO HOW ARE YOU?" | tr '[:upper:]' '[:lower:]' ...
0
votes
0answers
16 views

display JPEG Exif header with od (Octal Dump)

there are several command line tools to show Exif header of JPEG images. I wish to see the same info with od (octal dump) $ jhead 1430472877538-0.jpg File name : 1430472877538-0.jpg File size ...
0
votes
1answer
55 views

How to execute shell commands in a loop from within a bash script?

I am new to bash and need help badly. I want to write a script which will run on my android phone & perform the following things: echo "1" > /sys/kernel/mm/ksm/run wait for 2 minutes: then ...
2
votes
3answers
200 views

How to pass argument with char ( in remote path?

I'm trying to move a file with rsync to a remote location, The file has be be named : DRRS_(H264).mp4 but when I try : rsync -azR output.mp4 user@server.com:encoded/somepath/DRRS_(H264).mp4 it ...
1
vote
2answers
133 views

How to generate a random string in a profile alias?

I have an alias in my server's /etc/profile which generates a random directory on command, like this: alias rdir="mkdir -p ./`cat /dev/random | tr -cd 'a-z0-9' | head -c 8`/" But it turns out this ...
0
votes
1answer
35 views

Writing an install script for CentOS

Every time I deploy a VPS server, I install VNC server. But every time I have to do this: yum groupinstall Desktop yum install tigervnc-server yum install vnc yum install firefox (etc.) Can I ...
0
votes
0answers
16 views

Why rsyslog leaves the last file in spool directory

Suppose I am using a rsyslog remote server (R1) & have a client box (C1). C1 is configured to sync up and use R1 for logging (over port 514; TCP) The spool directory is '/var/log/rsyslog'. Now, ...
1
vote
2answers
24 views

How can I properly escape a string to be passed to a shell with a command argument [duplicate]

How can I properly escape arbitrary commands? For example: sudo -u chris sh -c 'echo "\"leftright\""' The above echos: "leftright" How would I echo out: "left'right" I've tried the ...
2
votes
1answer
93 views

Finding out what sh is [duplicate]

I am writing a set of scripts that I want to be portable, but I need to know whether sh on the current platform stands for bash, ksh, or ash. Is there a clear way to do it? What comes to my mind ...
0
votes
0answers
17 views

What does a hash key preceded by an exclamation key (!#)mean? [migrated]

See the following script from scala tutorial, What does the !# mean? #!/bin/sh exec scala "$0" "$@" !# object HelloWorld extends App { println("Hello, world!") } HelloWorld.main(args)
3
votes
4answers
162 views

Comparing each file in two directories and copying it to one if it differs from it's counterpart

How can I compare all files in two directories and copy the ones that are different to one of the directory. For example, say we have dir1 and dir2: dir1: build.gradle gradle.properties ...
0
votes
2answers
65 views

Shell Script: Sending input to background process

I am using the following script to watch a folder, and if the size changes and a file doesn't exist, it runs a script. #!/usr/bin/sh SCRIPT="dim_import/xdir" while true; do size=$(du -s ...
2
votes
2answers
69 views

How can I setup a separate bash environment with only GNU utilities on OS X?

For the last 5 years, I have used linux as my everyday OS for performing scientific computing. My work recently gave me a Mac that I will be the primary user for the next few months. I keep running ...
4
votes
2answers
76 views

Is it possible to escape quotes within escape quotes within escape quotes within escape quotes?

I'm guessing someone will tell me I'm doing something wrong and dumb and noobish, but I'm trying to script something in the most straightforward method possible and use sudo commands to do something ...