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
1answer
99 views

Shell namespaces

Is there a way to source a shell script into a namespace, preferably a bash shell script but I would look into other shells if they had this feature and bash didn't. What I mean by that is, e.g., ...
4
votes
1answer
88 views

making the current directory as if it were where absolute path starts

I'm wondering if there is an app that makes it so that commands after it operate in an environment that treats the working directory as if it were the top-most one, and there is absolutely no way to ...
1
vote
1answer
26 views

Exporting a function from .profile/.bashrc

What am I doing wrong...? It's fine if I do this on the command line and then call it but not when I load it from .profile. Linux Mint Qiana, Bash 4.*, if it matters. function android() { command ...
4
votes
1answer
55 views

using pipe to run command in background

I was reading this question on rpi and noticed an interesting line that got me thinking: mkfifo tcp.stream nc -l -p 1234 > tcp.stream | omxplayer --live tcp.stream Notice the io redirection. ...
5
votes
1answer
92 views

Logging bash output to a file

I'm trying to build vlc which is rather complicated and dependent on having the right packages installed, and keeps choking on errors. To trace all my steps I wish to output what I'm doing to a ...
3
votes
1answer
39 views

Parameter expansion in variable assigned with a wildcard

I have two files in my current folder (MA502) whose names are - MA502_TAAGGCGA-TCGCAGG_L001_R1_001.at.fastq MA502_TAAGGCGA-TCGCAGG_L001_R2_001.at.fastq I have many such folders - ex MA503, MA504 ...
1
vote
0answers
21 views

csh: How to save the shell environment (env, current dir, shell history) in a file and set it on another shell?

I start interactive terminal using farm (LSF). These terminals get opened on some random host and get closed automatically after 15 days. I want to save the current shell environment (env, current ...
0
votes
0answers
14 views

Getting CRC mismatch warnings in gdb on cygwin

When I run any program under gdb in cygwin shell I get following warnings... warning: the debug information found in "/usr/lib/debug//usr/bin/cyggcc_s-seh-1.dll.dbg" does not match ...
2
votes
1answer
30 views

View remote value of $PATH inside shell script

When executing this bash script, it only shows my local path. ssh ${REMOTE_HOST} 'bash -s' <<EOL set -e source ~/.profile echo $PATH # Commands here don't work because $PATH is ...
2
votes
3answers
231 views

copy all files that have no extension

We can copy some file by extensions like this: cp *.txt ../new/ but how can I copy all files that have no extension?
10
votes
3answers
761 views

How to understand “cat > file_name << blah” command?

In following command cat takes the content of here-doc and redirects it to file named conf: cat > conf << EOF var1="cat" var2="dog" var3="hamster" EOF How to understand the order of ...
0
votes
1answer
26 views

Running multiple commands at the same time

I want to run two commands on terminal on my virtual machine at the same time. I have this as of now: sudo ptpd -c -g -b eth1 -h -D; sudo tcpdump -nni eth1 -e icmp[icmptype] == 8 -w capmasv6.pcap ...
1
vote
2answers
63 views

Difference of using () and $() to execute a series of commands

I am currently trying to make a script that creates bytes that will be piped as input to netcat. Here is the idea of the script: (perl -e "print \"$BYTES\x00\"; cat file; perl -e "print \"More ...
4
votes
3answers
166 views

How to print control characters with escape sequences?

I have defined the color red using tput red=$(tput setaf 1) to colorize warnings in my program. This works fine: printf '%sfail\n' "$red" # prints 'fail' in red But on one occasion I would like ...
1
vote
3answers
73 views

For loop for a set of variables

I would like to run a for loop for a set of variables which I incorrectly denote as {A,B}. Following that my script looks like: #!/bin/sh for {A,B} in {1,2} {3,4} {5,6} {7,8} do echo A=$A B=$B ...
3
votes
3answers
91 views

How to kill this process in bash

I am trying to interface my homemade Raspberry Pi-powered arcade machine with a coin acceptor, and for that I: use a shell script (named gameplay) which starts the game emulator (MAME) when a coin ...
-2
votes
1answer
36 views

Execute bash snippets directly in shell? [on hold]

Is there any way to execute small bash snippets in the shell? If you don't want to edit a file again and again and test it by executing it again and again (in fact by jumping forth and back between ...
2
votes
3answers
40 views

Find a directory which contains all the files in my list

I have moved a file, which makes a reference to four other files with the same parent directory. And now I am stock trying to figure out which parent directory that is since there a number of files ...
0
votes
2answers
30 views

How to find file that has read permissions from root directory?

I am trying to find files with read permissions from root directory and save them under /home/student/abc direcory: find / -type f -perm a+r -exec cp /home/student/abc {} + but it shows me the ...
18
votes
1answer
411 views

What does it mean to have a minus sign as the first character of a command in htop output?

In htop, or other commands that show process status, all bash processes have in the command column /bin/bash but one process has in the command column -bash What does it mean?
4
votes
0answers
88 views

Peculiar Solaris integer comparison behaviour

This one caught me unawares! We have a Solaris machine (version: SunOS 5.8) hosting a pivotal script/process which has been running for many years without complaint. We recently had cause to have a ...
4
votes
3answers
274 views

Exiting a shell script with nested loops

I have a shell script with nested loops and just found out that "exit" doesn't really exit the script, but only the current loop. Is there another way to completely exit the script on a certain error ...
2
votes
1answer
29 views

Start sh in a specified directory from inittab

I am currently working on an embedded Linux system. For it to be similar to our other products I need to have it start a shell in a specified directory on boot, accessible using the serial port. For ...
-4
votes
0answers
17 views

create crontab job scheduling every day 10:44 AM in shell scripting [closed]

crontab job scheduling every day 10:44 AM in shell scripting
2
votes
2answers
60 views

What's the appropriate way to do “mv ./* ./subdirdir/”? [duplicate]

Under the current directory I have a number of files, and one directory. I would like to move all files to the sub directory: mv ./* subdir/ cannot move ./subdir to a subdirectory of itself... The ...
-5
votes
0answers
19 views

terminate when user type -1 [closed]

#!/usr/bin/env bash # Above, get the path to BASH from the envvironment. # Below, you could just set the total mileage here. total_mileage=0 # Below, start from zero and count up for the three ...
2
votes
1answer
16 views

Running make for LFS complains about [ and about missing gawk

I'm having a strange error when I'm trying to start the make process for LFS using the LiveCD SVN Trunk. When I go to run make it gives me; $ make /bin/sh: 1: [: -ne: unexpected operator -e Missing ...
-1
votes
2answers
41 views

shell script not running using crontab

This is my script mboxutil -l > n.txt sed 's/^.*user//' n.txt > n1.txt cat n1.txt | sed 's/^.//' > n2.txt sed 's/\/.*//' n2.txt > dss_list.txt rm -f n.txt rm -f n1.txt rm -f n2.txt sed ...
6
votes
3answers
272 views

Should I use a slash at the end of path variables in shell script or not? [closed]

Today when writing my shell script. A question suddenly comes to my mind. Since cd /target_dir and cd /target_dir/ both works. Should I add a slash at the end of my path variables in a shell script? ...
1
vote
1answer
43 views

Batch move all files from subdirectories to parent directory, but files have same name

I have many files in sub-directories that I would like to have all moved to the parent directory. Ex: 20150530XXXX/1.jpg 20150530XXXX/2.jpg 20150530XXXX/3.jpg 20150530XXXX/4.jpg 20150531XXXX/1.jpg ...
4
votes
3answers
158 views

awk and newlines in the input data

I want to find files in a directory and identify by their mimetype, not by the extension of the files. I'am using this command to determine the mime type: % find . -type f -print0 | xargs -0 -I{} ...
6
votes
4answers
818 views

Add a newline into a filename with `mv`

It's a serious question. I test some awk scripts and I need files with a newline in their names. Is it possible to add a newline into a filename with mv? I now, I can do this with touch: touch ...
13
votes
1answer
172 views

Update bash history on others terminals on exit of one

I know this question has a similar interpretation, as its asked here keep updating (and duplicated here). But what I'm trying to achieve is a bit different. I don't like the idea of my prompt ...
0
votes
1answer
46 views

Issue a command in each directory

I have 3 directories: dir1 contains two subdirs. In every subdir there is a slackbuild. I want to build all slackbuilds, staying in the parent directory. I have tried (cd *;sh *ld) But it only ...
0
votes
2answers
51 views

How do you search ! in man sed?

You cannot search ! directly because it puts process behind. For instance, you cannot search ! in sed man. How can you search ! in man?
2
votes
1answer
65 views

Convert IP Address to Coordinates using database

I have a file which contains IP and I wanted to compare it to Coordinates using a local database (instead of API). I tried following a process and break down to pieces and created scripts referring ...
0
votes
1answer
44 views

Practical usage of “shift” shell builtin command?

I checked the /usr/bin/ssh-copy-id(part of openssh-client package at least under Debian) shell-script and it contains following if-statement: if [ "-i" = "$1" ]; then shift # check if we have 2 ...
2
votes
2answers
52 views

ssh command with quotes

I have an odd error that I have been unable to find anything on this. I wanted to change the user comment with the following command. $ sudo usermod -c "New Comment" user This will work while ...
5
votes
6answers
495 views

How do I check if a variable exists in bash?

I need to check a variable's existence in an if statement. Something to the effect of: if [ -v $somevar ] then echo "Variable somevar exists!" else echo "Variable somevar does not exist!" ...
1
vote
1answer
43 views

Move files from multiple directories to another system

Let's suppose I have a folders in the source system: AB1, AB2, AB3. And I have the same folder names AB1, AB2, AB3 in the destination system. I want to move AB1 files to AB1 and AB2 files AB2 and ...
1
vote
2answers
53 views

How do i search for certain sections of a file and then extract only relevant information within that section?

So I have a text file that is a server report and has about 1000 lines of information in it. I'm trying to write a script that can search the report for only certain pieces of information I'm looking ...
2
votes
3answers
135 views
+100

locate alias with find

On small systems where there is no locate installed, How would an alias look like that gets the same result as locate? I can imagine find can produce the same output so an alias could look like ...
-3
votes
2answers
40 views

Transform text records using only a “for” loop

I have an input file that is text, consisting of lines that look like: 352|C|PAID|7036|VOICE|01-FEB-12 I need to split each line into fields at the | (vertical bar) characters and output each field ...
4
votes
2answers
41 views

How can I disable bash traces?

For any command that I execute in the terminal a comment like + command appears. For example for ls it shows + ls --color=auto.
3
votes
5answers
107 views

How to add column in the beginning of file using perl?

I want a Perl one-liner that checks whether the first fields of an input file is the file's name and, if it isn't, adds the file name as the first column on every line. Example written in shell : ...
0
votes
2answers
28 views

Does kali distro not use /etc/environments file?

I appended a path to /etc/environments file and now it is like so: mindaugas@Kali:~$ cat /etc/environment | tr ":" "\n" PATH="/usr/local/sbin /usr/local/bin /usr/sbin /usr/bin /sbin /bin /sbin" I ...
1
vote
2answers
42 views

Unable to store ascii value in a variable

I am trying to convert hex to decimal to ascii and store it in a variable. I am using the following code. HEX=30 DEC=`printf "%d\n" 0x${HEX}` echo "$DEC" ASC=`printf \\$(printf '%03o' $DEC)` echo ...
-5
votes
1answer
42 views

Copying and relative Home

Your current directory is oxford. Make a copy of the file named outline.doc and place it into the sample_dir directory, using relative pathnames. I've attempted everything. sample_dir1 `-- ...
0
votes
1answer
27 views

Combine curl and base64 into one command?

I'd like to POST the Base64 encoding of a file to a server, combining curl and base64 into one command that I can execute. I've tried the following: curl 'http://localhost:5000/files' -X POST -H ...
0
votes
1answer
32 views

What is the behaviour of & operator [duplicate]

I am trying to chain the commands in linux, I am using ubuntu 14.04 distribution. The aim to create a directory and go into that directory. Generally we do this mkdir foldername cd foldername ...