The shell is unix's command-line interface. You can type commands in a shell interactively, or write scripts to automate tasks.

learn more… | top users | synonyms (1)

0
votes
1answer
33 views

How to write simple if condition in ash?

I would like to write a small script that would check every once in a while if I have the internet connection. I would like to run it in crontab on my router where I have ash. I am having a hard ...
5
votes
5answers
158 views

Automatic transformation of newlines in shell variable assignment

This came out of one of my comments to this question regarding the use of bc in shell scripting. bc puts line breaks in large numbers, e.g.: > num=$(echo 6^6^3 | bc) > echo $num ...
2
votes
2answers
86 views

Unicode text doesn't appeared correctly in shell

I'm using the terminal in Kali Linux and I try to type Arabic text the characters are shown but separated (appearance not correct) This what my shell shows me ex. لا ا ل ه ا لا ا ل ل ه, which should ...
0
votes
2answers
86 views

Using grep to find first two numbers of IP addresses?

I'm trying to figure out how to use grep to pull out only the first two numbers of an IP address in a list. I've got a routine that is isolating the log entires (from Exim) that I need, now I just ...
6
votes
1answer
187 views

What is the rationale for the bash shell not warning you of arithmetic overflow etc.?

There are limits set for the arithmetic evaluation capabilities of the bash shell. The manual is succinct about this aspect of shell arithmetic but states: Evaluation is done in fixed-width ...
4
votes
2answers
141 views

Replace string with sequential index

Can someone suggest an elegant way to accomplish this? Input: test instant () test instant () ... test instant () //total 1000 lines output should be: test instant1 () test ...
5
votes
4answers
103 views

How to quote a string containing dollar sign $ and single quote '?

My directory's name contains a $ and ', for example :~$ export DIR=\$my\'dir :~$ sh -c "ls $DIR" How can I run above command without $my being expanded? I know the single quote doesn't work since ...
2
votes
1answer
86 views

There are stopped jobs (on bash exit)

I get the message There are stopped jobs. when i try to exit a bash shell sometimes. Here is a reproducible scenario in python 2.x: ctrl+c is handled by the interpreter as an exception. ctrl+z ...
1
vote
1answer
69 views

crontab is giving only 2045 lines of output instead of 6000 lines

I am executing one shell script with crontab which has to give more than 6000 lines output only it is giving output up to 2045 lines then coming out. when I run that shell script it is working fine ...
0
votes
2answers
47 views

How to match stream against white-list and black-list?

How can I duplicate a pipe stream (output from another program) so that for every line, I can check whether it matches independent regular expressions (ideally, reuse a grep command with options like ...
4
votes
5answers
98 views

Semi-asynchronous pipe

Assume I have the following pipe: a | b | c | d How to wait for completion of c (or b) in sh or bash? This means that script d can start any time (and does not need to be waited for) but requires ...
4
votes
1answer
134 views

Why do piping and redirection work differently with here documents?

Combining a redirect with a here document seems logical enough: $ bash > foo <<EOF echo Hello EOF $ less foo Hello But with a pipe it behaves differently: $ bash | tee foo <<EOF ...
2
votes
2answers
46 views

join sed output

I'm looking to somehow pass the output of the following command: $ sed -n '5p' file-A into $ sed '5 c\ > "string extracted from previous sed command" file-B So basically, I want to replace ...
1
vote
0answers
45 views

Merge several files with maximum 1 line difference

Suppose I have the following files: file0.c: int b=NULL; int a=NULL; file1.c: int b; int a=NULL; file2.c: int b; int a=NULL; I am looking to merge the files file1 and file2 to generate the ...
2
votes
1answer
17 views

can't change user

I setup vsftp with my ftp users' home directory at /var/www but I realized, it wouldn't let em login by ftp, I tried to connect to 127.0.0.1. So then i wanted to "try out" my ftp user on the shell but ...
2
votes
1answer
82 views

When should you use subshells vs `xargs`?

Many simple commands using xargs could be rewritten as commands using subshells. For instance, here is something I was using earlier today, to concatenate the ten largest binaries in /usr/bin, written ...
1
vote
1answer
49 views

How to control buffering of pipes in bash scripts?

I need my script to be executed with stdbuf -i0 -o0 -e0 otherwise user will wonder why there is no output (becuase of pipe buffer). How can I acheive it? #!/usr/bin/stdbuf -i0 -o0 -e0 /bin/bash ...
1
vote
1answer
50 views

Assignment to variables

I was trying to devise a solution to a different question asked on the site and came across this curious issue. Here is the set of commands that I issued: $ foo=82a9948422 $ echo $foo 82a9948422 $ ...
0
votes
1answer
41 views

Limiting grep search

Please help! Must use grep for this assignment. Must control grep function to search for a string strictly in a given field (Sadly no delimiters) Search field is characters 12-26. Must check if user ...
2
votes
2answers
78 views

Command-line editing vim style [duplicate]

I recently discovered terminal's feature, you can set the keys emacs or vi style I prefer the second. so if you do set -o vi You can use k j l h keys to navigate on the command line. And you can ...
0
votes
2answers
56 views

Why does kill not have a parameter for file and not for port number?

If I want to stop a program given its tcp port number or its file or named executable, can I run something like kill -tcpPortNumber $1 where the parameter $1 is a tcp port number or kill -filename $1 ...
2
votes
1answer
66 views

Copy files based on date/time from subset of directories

I'm teaching a class where (~80) students are submitting assignments that I can access via webdav, organized by student in directories named by their unique identifier. The students are split into ...
2
votes
2answers
58 views

How to change “date modified” of multiple folders, to be the same of that of a .mkv that's inside each one, using Cygwin

How to change "date modified" of multiple folders to be the same of that of the .mkv that's inside each one. eg. there's folder1 which contains a file 1.mkv folder1: 2/17/14 1.mkv: 1/6/12 I want ...
3
votes
3answers
123 views

Shell Script to move folders containing a specific word

I'm searching for an simple shell script to mv all folders in /var/www/uploads/ that containing Math or Physics in the name to /mnt/Backup/. I've never done something like that before, due to the ...
9
votes
2answers
182 views

How can I redirect `time` output and command output to the same pipe?

Suppose I have a binary called foo. If I want to redirect the output of foo to some other process bar, I could write ./foo | bar. On the other hand, if I wanted to time foo, and redirect the output ...
2
votes
2answers
82 views

delete old log files except the last one (alphanumerically sorted)

I have a number of log files in the form: log.2014-02-19-10_24_22 I.e. log.YYYY-MM-DD-H24_MI_SS The date that's part of the log file's name is when the log file was first created. So at any given ...
0
votes
0answers
253 views

Combine multiple CSV files as a Single Multisheet Excel file in Bash [on hold]

I need to convert multiple .csv files as a Single Multisheet Excel file in Linux using bash. Example: I am having Few .csv files like file1.csv file2.csv .... file80.csv. Is there any solution to ...
1
vote
2answers
38 views

Why are user account on remote server called shell account

Why are user accounts on a remote server called shell account , remote account sounds like a more intuitive name what is the reason behind this very unintuitive name ???
3
votes
4answers
66 views

how to rename files while copying?

How would I copy (archive style where date isn't changed) all the files in a backup directory to the user's directory while renaming each file to remove the random string portion from the name (i.e., ...
2
votes
3answers
255 views

How to login as root from Bash and do stuff

This is my simple bash: cat test.sh #!/bin/bash echo "hello" su - root -c /path/to/script.sh <<EOF password EOF whoami echo "good bye" But I get this error: ...
7
votes
2answers
176 views

Kill a process if it goes quiet for a certain amount of time

I have a utility that has a nasty habit of going quiet and staying there, I already know how long into the process it does this so I am using timeout to fight this, but sometimes it does it before ...
0
votes
1answer
19 views

Unrecognized Type: for length of date string [closed]

I am getting current date and checking for length of date if non-zero then perform some action. now=$(date) echo "$now" if [[ -n "$now" ]]; then echo "not empty" fi Prints this to console- Mon ...
12
votes
3answers
511 views

Two find commands comparison

Recently I received this find one-liner, but I'm not able to explain where the difference of the below two comes from: Example 1 [root@centos share]# find . -exec grep -i "madis" {} /dev/null \; ...
1
vote
1answer
73 views

Setting the bash SHELL for remote openSSH connections?

I am connected to a Freebsd 10 -STABLE server with SSH from my office box but when I trying to work inside the session I encounter these problems: although I did chsh for every user in said server ...
3
votes
5answers
333 views

Counting files in folder without wc

Why does the following scripts give a count of 0 instead of giving the count of files present in the directory? #!/bin/bash cd /root/Jamshed/script count=0 ls -lrt > all_files cat all_files | ...
2
votes
1answer
36 views

Ignore file changes

I have a process, which generates a file with configuration data and then calls a subprocess with this data as parameter. I'd like to override the configuration data, which is passed. The problem is, ...
1
vote
1answer
27 views

How can I add autocomplete for “gem which” with rbenv?

I am using rbenv on Mac OS X. I have autocomplete functionality already for the gem command: $ gem build environment lock query stale cert fetch ...
4
votes
2answers
132 views

Dump process's stdin and stdout

I have two processes, let's say Parent and Child. Parent launches the Child and communicates with it through child's stdin and stdout. Parent <-> Child These processes use text protocol and I ...
5
votes
2answers
62 views

Default preference of executable over built-ins with the same name

I was playing around a bit with the names of some executables, putting them in a folder, ~/bin, which is in my $PATH. Now I'm wondering how I can set the preferences of a bash-3.2 terminal so that it ...
1
vote
3answers
279 views

php shell_exec() permission on Linux Ubuntu

I'm developing a php application using Linux server. My problem is executing shell_exec() to call some exe file is not work(actually not exe, it's kind of linux executable file) echo ...
3
votes
2answers
118 views

Unit multiplier conversion in a shell script

I need to convert human-readable sizes into bytes. Unfortunately numfmt function is not accessible for me. Is there any other alternative? I need a shell/bash function to call from inside the sh ...
-2
votes
1answer
28 views

Implementation Logic [closed]

I have two files,which is something like this: file1 msgid "New" msgstr "" dsvhuvchvdhcvhc msgid "Old" msgstr "hsvhs" kdnvcjdbvj msgid "Bold" msgstr "" file2 dcbjdsbc msgid "New" msgstr "Alas" ...
-1
votes
4answers
58 views

Using 'find' to create text file, and later deleting files listed

I'm trying to use find to create a text file with the result. And then later be able to delete files, based on that list. I'm using find /volume1/video/ -iname "sample" to give me the results. How do ...
1
vote
1answer
29 views

Pressing tab after sourcing script file prints script related output

I have a script file in a directory. Its contents are as follows : #!/bin/bash ...
1
vote
0answers
54 views

What happened with my SHLVL? [closed]

I was messing around with my bashrc, finding better ways to start a newer version of bash. Never mind my tests. But this strange thing happened, which I like to understand: $ bash ## Probably where ...
1
vote
1answer
76 views

How to get the JSON STRING from the given string

I have a string given below. I just need to get the first accountHeader (bolded) JSON string, I tried everything.. It didn't work. Can you help me to get the data? <START ...
0
votes
0answers
39 views

usermod -L after creating the home dir

so I see from some questions here, to lock an account, create it, then lock, e.g. useradd -M lol;usermod -L lol However.. I do have a home dir, by eg. useradd -md /path/lol Question is.. to avoid ...
3
votes
1answer
105 views

How can I forward a already forwarded ssh key into tmux?

I'm connecting through SSH from a machine where my keys are stored, forwarding to a second machine, and then try to use the keys from within tmux. I appear to "loose" the forwarding when entering ...
1
vote
2answers
41 views

Make Trickle get the correct $PATH

Trickle is a bandwidth limiting program. I have the following script for trickle. #!/bin/bash echo $PATH trickle -s -t 3 -u 200 -d 200 "$@" I have a script in ~/bin/ that want to run the script ...
2
votes
1answer
58 views

< and << in UNIX /Linux

What is the option <<and < are used in linux for??? For example cat << abc.txt I know its a stupid question, but i was not able to search it on google as i did not know what ...