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
0answers
13 views

How to read and do a min/max/avg from a NMEA stream

I have a weather station attached to my device spitting NMEA 0183 on /tty/USB0 I have alreeady sorted out how to parse the data and echo what I want in a script. What I need to do now is write the ...
7
votes
2answers
404 views

Expand subshell before executing it?

I often run commands using subshells, and sometimes would like to have the subshells expanded before I run something.. This way I could verify what I'm doing, and possibly edit what's about to happen ...
2
votes
3answers
57 views

Can't login to server with SSH because of a script in /etc/profile.d exiting with exit status 1

so I have this problem, I can't login to my server with SSH. See: ssh -v myuser@myserver debug1: Authentication succeeded (password). debug1: channel 0: new [client-session] debug1: Requesting ...
0
votes
2answers
44 views

Explain the shell command: shift $(($optind - 1))

I am not a Linux guy but stuck in some Script which I have to read for my Project. So can anyone can help me what this command is doing? shift $(($optind - 1))
3
votes
2answers
6k views

Shell script throws a not found error when run from a sh file. But if entered manually the commands work

Im trying to use the following script to generate a sitemap for my website. When I run it as sh thsitemap.sh I get an error like this and creates an empty sitemap.xml file : thsitemap.sh: 22: ...
0
votes
4answers
89 views

The first Line of Scripting [duplicate]

what does #!/bin/bash at the 1st line mean ? Is it just a comment and ignored by the shell like all other comments in program OR Only this line is interpreted by the interpreter and all the other ...
-4
votes
1answer
40 views

What does ps aux | sort -rk 3,3 | head -n 5 meant? [on hold]

What does command ps aux | sort -rk 3,3 | head -n 5 do ? Please explain each command .
1
vote
1answer
33 views

Can see file in /usr/local/bin with ls, but attempting to run it yields file not found?

I'm on OS X, but since this is terminal work I figured this was the best place to ask. I'm trying to get Sublime Text to work at the command line via subl and having no luck. I ran ln -s <location ...
1
vote
2answers
46 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 ...
0
votes
2answers
20 views

Working with exporting PATH CentOS strange behaviour

I am trying to modify the PATH variable in two different scripts located in /etc/profile.d/ /etc/profile.d/php.sh #!/bin/sh PATH=$PATH:/usr/local/php/bin export PATH /etc/profile.d/mysql.sh ...
4
votes
1answer
145 views

Making the current directory as if it were where an absolute path starts

I'm wondering if there is an application 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 ...
8
votes
1answer
202 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., ...
13
votes
3answers
20k views

how to output text to both screen and file inside a shell script?

Currently I have a shell script which logs messages to a log file like this: log_file="/some/dir/log_file.log" echo "some text" >> $log_file do_some_command echo "more text" >> $log_file ...
4
votes
1answer
57 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
96 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 ...
7
votes
3answers
9k views

How do I change folder timestamps recursively to the newest file?

I was wondering if anyone knows how to change the timestamps of folders recursively based on the latest timestamp found of the files in that folder. So for example: ...
3
votes
1answer
40 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 ...
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
235 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?
11
votes
2answers
19k views

How do I check if a file is a symbolic link to a directory?

I can check, if a file exists and is a symbolic link with -L for file in *; do if [[ -L "$file" ]]; then echo "$file is a symlink"; else echo "$file is not a symlink"; fi done and if it is a ...
1
vote
0answers
23 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 ...
5
votes
1answer
260 views

Whenever I type some wrong command, my terminal tries to run that command in the background

Something strange started happening to my terminal. Whenever I type some wrong command it tries to run that command in the background. hegeek@colinux: ~# l [9]+ Stopped l thegeek@colinux: ~# ...
10
votes
3answers
781 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
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 ...
0
votes
1answer
28 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 ...
2
votes
2answers
65 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
170 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
76 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 ...
2
votes
3answers
163 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 ...
139
votes
16answers
81k views

How to do integer & float calculations, in bash or other languages/frameworks?

Using echo "20+5" literally produces the text "20+5" What command can I use to get the numeric sum, e.g. 25 in this case. Also, what's the easiest way to do it just using bash for floating point, ...
3
votes
3answers
92 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
3answers
2k views

Find functions, commands, and builtins [duplicate]

Possible Duplicate: Executing user defined function in a find -exec call Suppose I have the following bash code: !#/bin/bash function print_echo (){ echo "This is print_echo Function" ...
0
votes
2answers
3k views

variables in find command and more shell problem [duplicate]

Possible Duplicate: Recursive rename files and directories I wrote the following script: #!/bin/bash SAVEIFS=$IFS alias export='export' IFS=$(echo -en "\n\b") find $1 -name "*" ...
2
votes
2answers
61 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 ...
28
votes
7answers
41k views

Execute a command once per line of piped input?

I want to run a java command once for every match of ls | grep pattern -. In this case, I think I could do find pattern -exec java MyProg '{}' \; but I'm curious about the general case - is there an ...
0
votes
2answers
537 views

Making A Shell Script To Write To XML File

I am writing a shell script to make writing my RSS a whole lot easier. Right now I am stuck at how to properly edit my files. See, I want the program to take in data from me, and then save those to ...
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 ...
5
votes
1answer
96 views

Bash Script — ffmpeg not being invoked as expected

I'm working on a bash script to convert my music library to ogg* but executing the right command is somehow eluding me. This is the line that should accomplish it: ffmpeg -i "${file}" -f flac pipe:1 ...
4
votes
3answers
278 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 ...
-1
votes
2answers
43 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 ...
18
votes
1answer
427 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?
-2
votes
1answer
37 views

Execute bash snippets directly in shell? [closed]

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 ...
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 ...
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 ...
70
votes
16answers
69k views

How can I get distribution name and version number in a simple shell script?

I'm working on a simple bash script that should be able to run on Ubuntu and CentOS distributions (support for Debian and Fedora/RHEL would be a plus) and I need to know the name and version of the ...
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
0answers
17 views
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 ...
6
votes
4answers
819 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 ...
2
votes
1answer
66 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 ...