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)

6
votes
3answers
382 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
23 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
56 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
153 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
72 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
89 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
34 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
29 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 ...
16
votes
1answer
368 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
81 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
269 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 [on hold]

crontab job scheduling every day 10:44 AM in shell scripting
2
votes
2answers
59 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 [on hold]

#!/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
39 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
267 views

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

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
808 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 ...
12
votes
1answer
144 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
64 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
43 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
489 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
104 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
106 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
41 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 ...
1
vote
3answers
71 views

How do I get the current line count from xargs?

I want to grab every 5 images in a directory and merge them together into a new file with a unique filename per 5 image group. find *.jpg | xargs -n 5 -i convert {} -append {#}.png This is really ...
0
votes
2answers
30 views

Which file should be sourced in .devishrc to permanently change the hitch-file? [closed]

By default, in DEVISH (at least for me) the hitch file used is mhitch.py... I can change the hitch using the -h option for the shfile command, but I need to permanently set it to something... Any ...
0
votes
2answers
61 views

Bash script that detects if a file is the correct size

I'm trying to make this bash script dispatch and email when it detects that a certain type of file (files ending in ".gz"), which was last modified 24 hours ago, is below a certain size in a ...
2
votes
1answer
22 views

ssh not showing full output of command

I have a list of servers 20+ that I would like to get the shell that they are using. While logged onto a server I can run the following command $ ps -p $$ PID TTY TIME CMD 12022 pts/6 ...
1
vote
2answers
22 views

How to switch to bash on DEVISH?

With the update from BasilOS Quad to Pentus, DEVISH became the primary shell(replacing bash)... I am completely unfamiliar with DEVISH, so I need to be able to switch back to bash... I tried chsh but ...
2
votes
3answers
94 views

Delete several sequential file names, but ignore part of the first

Sometimes, my scripts get trapped in infinite loops. When the loop creates new files, things get messy. I currently have this file name format: Task.4883.store.log where 4883 is a counter. I ...
1
vote
1answer
35 views

Backquotes interpretation

I'd like to know what's the difference between these two commands: echo ` echo `date` ` echo ` echo \`date\` ` I know that \ is used to escape characters, but I cannot understand it in this ...
1
vote
1answer
52 views

change LS_COLORS behaviour

I am trying to modify LS_COLORS behavior. Presently it (say for sh or py), changes color depending on if it is executable or not, as shown here But, I want all my script, executable or not, have ...
2
votes
3answers
57 views

Execute a shell command upon a click event in a web page

Is there a way to execute a bash command when I click on a text in a browser? The web page is on computer A, the browser is on computer B : I want to execute the code on computer B, e.g hsetroot to ...
1
vote
2answers
35 views

/bin/sh - echo >> operator not working as expected

I'm writing a shell script that appends binary contents to a file. I tried using this command: echo -en '\x61\x62\x63..' >> /tmp/myfile but that caused the following output: -en ...