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)

3
votes
1answer
6k views

i/o format with printf in bash-shell

I am trying to output the results of my shell script using printf. To keep the results aligned in column, I am using tab as: printf "%s\t %s\t %s\t %s\t %s\t %s\t %s\n" $i $est $var_m $jk $mst $var_M ...
0
votes
1answer
38 views

Avoiding glob expansion in fgrep string

I'm working on a Busybox distro that lacks the crontab command. I want to create a bash script that updates root's crontab file with jobs listed in a text file. I've got most of the script working, ...
1
vote
2answers
40 views

compress all pdf files recursively

i want to compress all my pdf files in an given directory and its sub-directories using ghostscript. I´m stuck using the find command within loops by filename including spaces. Here some example ...
0
votes
1answer
49 views

Is it possible to put an if statement within an If statements like so?

As my title suggest I'm trying to put an if statement within an if statement. It seems to work until the last echo command in the script which doesn't print. For testing I have created a directory ...
28
votes
6answers
28k views

How can I play a sound when script execution is ready?

I am executing every now and then some python scripts which take quite long to execute. I execute them like this: $ time python MyScript.py How can I play a sound as soon as the execution of the ...
6
votes
5answers
3k views

Last failed command in bash

The $? variable holds the exit status of last run command. Is there a variable that holds last run command itself?
0
votes
0answers
15 views

How to escape special characters in gnu sed? [duplicate]

I have variables in shell: VAR_IN='Unsafe \t \ string I don't control.' VAR_OUT='some output' I need to change every VAR_IN to VAR_OUT in a stream. Idea is to: sed "s/$VAR_IN/$VAR_OUT/g" # this ...
89
votes
3answers
3k views

Security implications of forgetting to quote a variable in bash/POSIX shells

If you've been following unix.stackexchange.com for a while, you should hopefully know by now that leaving a variable unquoted in list context (as in echo $var) in Bourne/POSIX shells (zsh being the ...
3
votes
2answers
70 views

set environment variables from stdout

How can you do the equivalent of piping stdout to 'export'? For background, I have a non-shell script that generates environment variables like so: DATABASE_URL='someurl' MAIL_KEY='key' REDIS_URL='...
0
votes
2answers
54 views

Combination of tee and tty [on hold]

I tried the below command, I read it from a book sudo ls | tee /dev/tty3a This command gives to me Permission denied, even with sudo. Here tty is the teletypewriter, I know this already. But what ...
0
votes
2answers
16k views

Got “syntax error near unexpected end of file” in bash script

I'm making an script that gives me a day like this jjj/yyyy when I give it a day like this dd/mm/yyyy and I need it to have an error when you don't write correctly but I'm starting and it's not ...
0
votes
1answer
71 views

What exactly is | [on hold]

The symbol | when used in command line seems to redirect the output of one processes to another. I am wondering how it happens in terms of data forwarding from process on the left to right. Also what ...
3
votes
2answers
73 views

Run command in multiple active shells simultaneously

I am using tmux environment and often times I have to run the same python script in 4 different panes (top 4 in the image) with same command line arguments. Is there a way I can execute the script on ...
0
votes
1answer
25 views

Redirecting stdout and stderr still prints to stdout

I'm getting an some kind of error at the VGA console when I make a configuration file for grub (at least I think it's an error), with grub-mkconfig -o /boot/grub/grub.cfg I tried to redirect stderr ...
1
vote
2answers
32 views

Where can I find shell script for parse JSON on busybox?

I have an IP camera with armv5tejl architecture. There I have busybox. I have to be able to parse JSON responses from curl. The problem is that I don't have programs like: jq, jshon, jsawk... It is ...
3
votes
2answers
77 views

How to Run a command on all subfolders

If you have a series of sub folders (like from a to z) and want to run a command on each one of them (like dsmmigrate * & ) how do you do that? The manual approach would be, cd a dsmmigrate * &...
1
vote
2answers
48 views

How to test if a file starting with a particular prefix is present in a directory in shell script [on hold]

I need to test if a file starting with "ant" is present in the directory. If that is present, I need to delete that file. The command that I am using now is test -e $FILE_PATH/$FILE_NAME I have ...
176
votes
6answers
383k views

How do I grep for multiple patterns?

I want to find all lines in several files that match one of two patterns. I tried to find the patterns I'm looking for by typing grep (foo|bar) *.txt but the shell interprets the | as a pipe and ...
58
votes
5answers
21k views

Prepending a timestamp to each line of output from a command

I wish to prepend a timestamp to each line of output from a command. For example: foo bar baz would become [2011-12-13 12:20:38] foo [2011-12-13 12:21:32] bar [2011-12-13 12:22:20] baz ...where ...
4
votes
2answers
17k views

Shell Script - syntax error near unexpected token `else'

With the following shell script, why I am getting errors syntax error near unexpected token `else' Shell Script echo "please enter username" read user_name echo "please enter password" read -s ...
1
vote
2answers
38 views

Using “find” non-recursively?

Using /bin/find /root -name '*.csv' returns: /root/small_devices.csv /root/locating/located_201606291341.csv /root/locating/located_201606301411.csv /root/locating/g_cache.csv /root/locating/...
3
votes
2answers
49 views

Can I `join` against a command?

I find join pretty useful. It lets you join file1 against file2 on key fields. Is it possible to do so dynamically against the results of a command, like: join -1 1 -2 1 file1 'curl http://example....
2
votes
2answers
36 views

Default assignment to a null variable with command substitution

I'm trying to use the syntax: A=${B:-C} where A is the variable, B is the value I'm trying to assign, C is the default value if B is null. Now I want to replace B with the command nc -l 443, so if ...
0
votes
0answers
27 views

keep data in 4 digit in array or make data in 4 digite with out using printf, in sheel [on hold]

I need to download a lot a stuff from ftp, so I made a loop with array for the name of each file. The thing is the number from the array can not show as 4 digit, which the file name is (like 0030). I ...
2
votes
3answers
37 views

Specifying redirection options through a variable, in an exec command

I want to be able to specify the redirection command/options via a variable (that I might set based on certain conditions, etc.). But when I run this bash script for example : REDIRECT=">>test" ...
-3
votes
0answers
24 views

Need to create shell script to extract logfile and extract timing detail from it and copy it in excel file [on hold]

I need to copy a logfile (containing details of job run on recent date) from different directory to the current directory and from that logfile i need to find some particular job timing detail to ...
3
votes
5answers
195 views

Comparing multiple options in a bash (string)

I'm trying to enable only certain options when using the read command, and to exit the script if a wrong possibility was entered. Tried many possibilities (array, variables, syntax change), but I'm ...
-1
votes
1answer
20 views

xdg-open open Url in browser with & [on hold]

How To open Below Url in browser by using xdg-open. http://w57.myfranconnect.com/squirrelmail/src/read_body.php?mailbox=INBOX&passed_id=683&startMessage=1
1
vote
3answers
110 views

How complex can a program be written in pure Bash? [closed]

After some very quick research, it seems Bash is a Turing-complete language. I wonder, why is Bash used almost exclusively to write relatively simple scripts? Since a Bash shell comes with Linux, you ...
21
votes
3answers
37k 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 ...
-5
votes
0answers
28 views

I want to shell scripting can anybody assist me on this ? Any website or any online course? [on hold]

I want to shell scripting can anybody assist me on this ...Any website any online course.
2
votes
2answers
189 views

Renaming using terminal and regexp to remove leading numbers from filenames

I want the following files to be renamed removing the sequence numbers. 01 X.mp3 to X.mp3 02 Add Me In.mp3 to Add Me In.mp3 I am trying with the below rename command. rename -v -n 's/^\d+\s*([a-z]+...
-1
votes
1answer
55 views

How to grep and treat meta character as normal character? [on hold]

I am trying to recursively find some pattern which contains meta character. Pattern that I searching for is template <int N> I have tried : grep -F -lir "template <int N>" * # ...
21
votes
4answers
36k views

Why doesn't my ~/.bash_profile work?

I'm using Linux Mint. My login shell (cat /etc/passwd | grep myUserName) is bash. After I start my graphical desktop environment and run terminal emulator from it, I could see that .bash_profile is ...
4
votes
2answers
54 views

How can I stop vim from editing directories?

Sometimes I accidentally tell vim to edit a directory instead of a file in it vim directory-name # what I typed vim directory-name/blah.txt # what I meant to type Instead of immediately ...
3
votes
2answers
58 views

Echo the list of process not running

I have developed a script, the script refers to a file to start the required processes on that server. The script times out after 180 secs. At the end of the script I would like to display the ...
0
votes
2answers
928 views

Difference between 'echo' and 'echo -e' [closed]

What is the difference between echo and echo -e? Which quotes (" " or ' ')should be used with the echo command? ie: echo "Print statement" or echo 'Print statement'? Also, what are the available ...
4
votes
3answers
876 views

Unicode text doesn't appear 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 ...
11
votes
2answers
441 views

Is there a way for shell script to know which program has executed it?

In *nix world, is there a way for shell script to have information about which program has executed it? Example: /path/to/script1 /path/to/script_xyz in this imaginary scenario, script_xyz would ...
5
votes
2answers
60 views

How to set an alias across all tty shells?

I set an alias in shell tt2 but it won't work in other tty shells, any idea how to make a system wide alias ?
2
votes
6answers
141 views

Renaming files from upper case to lower case

I need to elaborate a little bit more. These commands are actually for a BBS FTN tosser. The configuration file for which these commands reside in, only allow specific declarations. Here are a few ...
6
votes
2answers
381 views

Why does changing $PATH affect child shells, but changing $foo not?

$ unset foo $ unset bar $ echo $foo $ echo $bar $ echo $PATH /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games $ foo=a $ bar=b $ export bar $ echo $foo a $ ...
4
votes
1answer
74 views

Exploit in bash script parameter possible?

I want to pass an e-mail address from a web form to a bash script. I'm using the following regex: /[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,4}/ Is this sufficient? Or could one embed an exploit?...
7
votes
1answer
159 views

Why does OS X `install` errors on redirected input when the same version of `install` on linux works fine?

I would like to use install command in order to create a new executable file with pre-populated content (e.g. with single pwd command in it). So I've extended this example which creates a new empty ...
7
votes
4answers
673 views

OpenSSH - map aliases in ~/.ssh/config to IP addresses in command line

Is it possible to query ~/.ssh/config in the command line? Let's say I would like to retrieve what IP address does the particular alias point to in a separate program, is it possible?
2
votes
1answer
61 views

Why do my single quotes vanish on substitution with sed

What is the right command for: sudo sed -i '/, false);/adefine( 'WP_MEMORY_LIMIT', '64M' );' /var/www/html/wp-config.php The result is: define( WP_MEMORY_LIMIT, 64M ); instead of the desired: ...
20
votes
6answers
31k views

In linux, how to delete all files EXCEPT the pattern *.txt?

I know how to delete all txt file under current directory by rm *.txt. Does anyone know how to delete all files in current directory EXCEPT txt file?
2
votes
2answers
583 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
99 views

tail file from remote server and nslookup on local

I need a script for resolve hosts. For now I run this script on local machine for i in `tail -F access.log | awk '{print $8}' | awk '{gsub("http://|/.*","")}2' | awk '{gsub("http://|:.*","")}1' | ...
1
vote
1answer
35 views

cat into stdin then pipe into program keeps forked shell open, why?

I'm not sure what's going on but I've been trying to understand what is happening with the input and output. So here is my program. #include <stdio.h> #include <stdlib.h> int main(){ ...