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)

7
votes
2answers
701 views

What is the value of ${#1}?

Please explain the usage of ${#1} below: getlable () { if (( ${#1} == 0 )); then test="-"; else test="${1}"; fi; }
0
votes
0answers
32 views

Pg_dump does not work in Cron

I have the command below and run it succesfully: /usr/lib/postgresql/9.1/bin/pg_dump -U dspace --format=c --file=/dspacebkp/dspace_db_$(/bin/date +\%m\%d\%Y)_uncompressed dspace I can see my new ...
2
votes
2answers
49 views

How to append data to a variable using \n as separator?

The new line characters seem to be lost, even though they appear within quotes. foo= for i in 1 2 3; do foo="$foo$(printf '\n')$i" done echo "$foo" 123 Now in practice, I don't want to add a ...
0
votes
0answers
31 views

Git “unknown revision” error when within bash script

I'm writing a shell script that needs to perform certain operations based on the last commit's message of my local branches with a name starting with "task". Here's what my script looks like ...
5
votes
5answers
332 views

How to group lines in file by two?

I have a text file like this: a b c d e f g How can I group those lines to obtain an output like this: a-b b-c c-d d-e e-f f-g I have to do this in shell (sh, csh, bash). I have found this: ...
3
votes
2answers
63 views

What does “if echo $line | grep -F = &>/dev/null” do?

I'm not sure what the following line does in a bash script: if echo $line | grep -F = &>/dev/null then ... I know &>/dev/null is short for >/dev/null 2>&1, I'm not sure, ...
0
votes
0answers
31 views

Is it possible to ssh and execute a remote command with a single quote in it? [duplicate]

ssh user@host "mv \"/some/path/fi\'le.txt\" /some/new/path" It doesn't matter what I do, or what combination of quotes I use on the file, it gives the following: bash: -c: line 0: unexpected EOF ...
213
votes
4answers
18k views

How does a Segmentation Fault work under-the-hood?

I can't seem to find any information on this aside from "the CPU's MMU sends a signal" and "the kernel directs it to the offending program, terminating it". I assumed that it probably sends the ...
1
vote
2answers
69 views

BASH how to save output of rm with timestamp?

I nearly have this working, This is a script that will run in CRON to keep the latest 10 backups, and remove anything else, I want to log this to keep track to make sure all is in good order, I have ...
4
votes
2answers
204 views

ps - what is the difference between -o comm and -o command?

On CentOS 7.0.1406 I get differing output when running ps -A -o pid,command | grep [r]esque than when I run ps -A -o pid,comm | grep [r]esque The latter returns nothing; the former what I would ...
0
votes
0answers
74 views

How to redirect linux command outputs to specific row and column in csv?

I'm working on Unix Build post documentation process, I have a CSV file to be filled in and uploaded for every new build, to ensure the servers are build as per the original request. The CSV file ...
0
votes
1answer
11 views

linefeed in bash script - to email

I am doing printf to a logfile and having that logfile send through mailx, however, it seems that the linefeed "\n" are not recognised or captured in the mail. Snippet of script as below (notice the ...
5
votes
2answers
39 views

How to store a path built with wildcards and containing with spaces into a variable

Here's the situation (I'm on a Mac, OS X El Capitan): # This works: $ cd /Applications/Adobe\ Illustrator*/Cool\ Extras.localized/en_US/Templates/; # These do not work: $ ...
2
votes
2answers
36 views

Find commands/function whose name matches a value

I am looking for some command e.g. match ls which should match commands like ls, alsa asls,.. and return them. I preferably want it to cover both all commands and defined functions. Is there a builtin ...
2
votes
2answers
24 views

exclude target redirection file from being processed in for loop

This will cause LIST to grow very large (even a couple of GB in a short time etc): $ for i in *; do echo $i; cut -d ' ' -f1 $i ; done > LIST For example, after 10 seconds: $ wc -l LIST ...
3
votes
4answers
67 views

Sticky entries in shell history

Is there a way one could make some commands "sticky" in a shell history? I want to save some favourite commands that would be searchable with Ctrl+R, like the rest of the history, but they should ...
2
votes
3answers
24 views

Extract lines from text with string as input

How can extract lines that match the regexp string ^li from the text (not a file) below using sed or something? linux loan litmus launch I tried grep but I couldn't find a way to search within ...
1
vote
1answer
24 views

Breaking out of a loop, return to start of loop with correct value of variable

I am sending processes to a server, but I only want a certain number running at a time. Thus I loop which checks how many jobs are running and only submits new one if the current amount of jobs do not ...
1
vote
0answers
17 views

How to switch to another screen to run git commands while resolving conflicts (blocking command)?

Often times, I work out of a single shell when I run git commands. For example, I will start a merge: $ git merge origin/master If during this merge there are conflicts, git will "block" the shell ...
0
votes
1answer
21 views

Trying to find the index of an entry in a list [duplicate]

I am trying to find the index of an list entry using this simple method: #!/bin/sh partList="500 1000 2000 4000" a=( $partList ) echo ${a["500"]} this returns Syntax error: "(" unexpected. And the ...
0
votes
1answer
42 views

set date time from user input in shell

I am creating script to check RTC working & for that first I am getting the date & time from user input in yyyy mm dd hh:mm:ss format. read -p "Enter the date:" val echo $val date -s "${val}" ...
1
vote
2answers
21 views

Copy plaintext lines from file and append them to same file with mid-line prefix or remove mid-line prefix

Making an ugly script that compiles a bunch of hosts files into one big list. Most lists will have two entries for a URL, one with www. and one without like this: 127.0.0.1 facebook.com 127.0.0.1 ...
5
votes
1answer
46 views

Ctrl+c and Ctrl+z to interrupt/suspend jobs

To kill a hanging job, I use Ctrl+c, to send an interrupt signal to the hanging job. Sometimes this wouldn't stop the job, at least not immediately. I can then use Ctrl+z to suspend the job and then ...
1
vote
5answers
262 views

To remove extra space from line using shell command

This is my file, TLRUIDA CBdms Status DP 6/1/1 DC 6/1/5 0 Y TLRUIDA CBdms Status DP 6/2/1 DC 6/2/5 0 Y TLRUIDA CBdms Status ...
-1
votes
2answers
34 views

ssh linux to mac inside and outside lan

Hi this is my first post and I was wondering if anyone can help me? I have ubuntu on my home pc and I want to be able to ssh to a macbook. When they are both on the same wifi network it's no problem, ...
1
vote
0answers
50 views

File exists but errors with “mv: cannot stat: No such file or directory”

For some reason my script cannot copy or move files that exist. It comes up with the errors below. Can someone tell me why? cp: cannot stat '/mnt/sd/bbu/install/scratch/bin/.': No such file or ...
2
votes
3answers
98 views

How to make xargs handle spaces and special chars from cat?

I have a file that contains a list of names. i.e.: Long Name One (001) Long Name Two (201) Long Name Three (123) ... with spaces and some special characters. I wanted to make directories out of ...
0
votes
1answer
24 views

Conditionals do not work in . ./script [closed]

I am trying to make a history file manipulations scripts. When I try to, for instance implement an incognito mode by running unset HISTFILE It doesn't work due to command running in new shell. ...
1
vote
2answers
27 views

Inline sound effect using command line

I found a while ago a way to modify recorded sound (pitch and such) and playing it through speaker in a single command line, involving "rec", piped to another command... But silly me, I didn't save it ...
1
vote
2answers
50 views

Backtick command encapsulation

test@debian:~$ echo `echo \`echo "uh!"\`` uh! How does the Bash do that? It seems that it first executes the expression in the non-escaped backticks, which gives back (the double-quotes "" are ...
0
votes
1answer
32 views

colored bash does not work as root user

I have noticed that when I ssh to a server and then su to the root user, I do not get color in bash. In this specific case when I say "do not get color in bash" I am talking about editing files with ...
10
votes
2answers
987 views

Is the “$?” (dollar-question mark) variable available only in the Bash shell?

In the Bash shell, I can get the command exit status through the $? variable: # ps -ef | grep "haha" root 15439 15345 0 23:02 pts/0 00:00:00 grep --color=auto haha # echo $? 0 Is it ...
3
votes
2answers
33 views

Why builtin times doesn't work in pipeline?

I've the following sample script: #!/usr/bin/env bash sleep 5 printf "times cmd: " times printf "pipeline: " times | ( read user sys; echo $user; ) printf "head: " times | head -n1 printf "times cmd ...
-1
votes
1answer
17 views

Lock a Application Through Terminal

I was wondering if it were possible to lock a Application through Mac Terminal. I know there's a way to lock files, using chmod a+x 000 'directory', but it never worked with an Application. What I ...
3
votes
2answers
43 views

Parameter expansion on multiple variables

Parameter expansion on a single variable works as expected. But how to expand parameters that comprise several variables? Example: #!/bin/sh foo=/lorem/ipsum; bar=dolor/sit tmp="$foo/$bar" printf ...
2
votes
4answers
94 views

Moving and renaming hundreds of .jpg files, all named 5003.jpg

So here's the deal, my girlfriend wants me to transfer all of her photos off from her iPhone onto her laptop (on which we are running Ubuntu 14.04). All of the dedicated programs I tried to do this ...
1
vote
2answers
37 views

What is the difference between . and the current directory?

I'm trying to copy the current directory as a source. Using full paths gives me the expected behaviour, copying the entire directory into the destination. $ cd /tmp $ mkdir a b $ cd a $ touch 1 2 3 $ ...
1
vote
2answers
88 views

Full file date (without GNU utilities)

I am trying to obtain the full date (created or modified) of a particular file for passing to another program. I have tried variations of options with the ls command but none provide a full date for ...
1
vote
1answer
58 views

how concatenate two commands?

Please can someone help me to concatenate two commands on shell, I'd have the path result and concatenate with the number of column in the first field. EX: #this gives me the path of my path ...
0
votes
2answers
19 views

Running shell job on remote server, closing terminal without closing job

I am running jobs on a remote server using torque. I currently have a an annoying problem. When I run my jobs this is what I currently do: Log into another computer via Teamviewer From that ...
0
votes
2answers
72 views

Parsing HTTP response with shell

I want to parse below HTTP response but I cannot figure out how to grep the values separately using a single curl request. I need these two output. 1. status_code - (Array of HTTP status codes) 2. ...
0
votes
1answer
36 views

How to store a variable that increments by the index?

I'm very new to programming and I was wondering how I could store and print the variables that are being incremented in bash. #!/bin/bash ethcounter=$(ifconfig -a | egrep --count "eth") ...
1
vote
0answers
14 views

Schedule (Cron) executing tasks based on bash scripts using CronniX

I'm still quite new you Mac and OS X but do have some background about other UNIX based systems, so please excuse for any misunderstandings. My goal is to implement a function that executes certain ...
1
vote
1answer
23 views

How to Load data to one table from Multiple excel files?

I have to load data from multiple excel file into one table , Please help me to achieve the solution. We are getting excel file from different retail shop which contain multiple column , each file is ...
1
vote
0answers
22 views

Start a subshell then run commands

Say I have a script that is always run from an interactive shell. I would like this script to launch an interactive subshell that is a replica of the parent (i.e., all environment variables, etc. ...
0
votes
0answers
28 views

ssh some commands through (a variable amount of) intermediary hops

(I hope I did search the se sites correctly to avoid duplicates: I did not find a similar question/need, and most similar questions only hop through 1 hop) : the need: I need ideas to create a way to ...
0
votes
1answer
15 views

Getting error while using httpd -v command in script

I wrote a script to check the details of Web server's(RHEL) and save the output into a file. But the script is not passing the command httpd -v in the loop. Here is the script. #!/bin/bash for i in ...
1
vote
2answers
17 views

Find unique lines based on only a section

I am wondering if there is a way to split lines by some character (E.g. :) and find unique lines based on one part of this split. For example if I had the following piped in via stdin file1: line 4 ...
3
votes
0answers
57 views

Shell Arithmetic Expansion with Quotes

In Bash and Dash, using quotes in an Arithmetic Expansion is illegal: $ bash -c 'x=123;echo $(("$x"))' bash: "123": syntax error: operand expected (error token is ""123"") $ dash -c 'x=123;echo ...
3
votes
3answers
154 views

Recursive Function not Working

I know that this is a ridiculous idea, but I'm trying to get a script to work that branches through every directory on the file system. The file's name is "Everywhere.sh". Here's the code: ...