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

Umask value isn't reflected after making changes

I changed umask from 002 to 007 in /etc/bashrc and in /etc/profile. After logging as a normal user I run umask, and it displays 0027. It should display 0007, but it doesn't. What should I do? if [ $...
2
votes
2answers
1k views

Trouble with mv and adding the date

I want to be able to move $oldfile to my backup folder and add the date to the file name. So I tried this... mv $oldfile /home/u0146121/backupfiles/$oldfile_$(date +%F-%T) This just gives me this ...
59
votes
6answers
101k views

How can I test if a variable is empty or contains only spaces?

The following bash syntax verifies if param isn't empty: [[ ! -z $param ]] For example: param="" [[ ! -z $param ]] && echo "I am not zero" No output and its fine. But when param ...
9
votes
5answers
9k views

Check if script is started by cron, rather than invoked manually

Is there any variable that cron set when it's running a program ? If the script is running by cron, I'll skip some parts; otherwise invoke those parts. How can I know if the bash script is started by ...
12
votes
4answers
38k views

sudo over ssh: no tty present and no askpass program specified

I keep getting this error and have tried several ways discussed online to fix this and none are working for me. I have setup SSH keys so when I run 'ssh newton@host.com' it automatically logs me in, I ...
1
vote
1answer
35 views

read the file and assign the values to another file

I want to read the file and assign the values to variables whic is in another file using shell script. For example I have file as "myconf" cli="/opt/Solartis_Monitoring/JON_CLI/bin/rhq-cli.sh" user="...
0
votes
1answer
37 views

how to change colors of my ps1 root terminal permanently [duplicate]

I want to change the colors of root@MyComputer:~#and when i type the ls command show me the result as colors! I write a simple BB code to display what i want: [color=red]root@MyComputer:[/color][...
18
votes
3answers
22k views

Is there a simple command for outputting tab-delimited columns?

E.g. I have a file (produced with echo -e "var1\tvar2\t\var3\tvar4" > foo) that are output as: $ cat foo case elems meshing nlsys uniform 2350 0.076662 2.78 non-conformal 348 ...
24
votes
9answers
23k views

How do I check if a variable exists in an 'if' statement?

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!" ...
15
votes
2answers
22k views

How do I unset a variable at the command line?

I have tried the following command to set Proxy on yaourt: export ALL_PROXY=http://proxy.example.com:8080 The question is how to unset the proxy on yaourt? In general, how can I unset the value of ...
11
votes
2answers
34k views

How to alter PATH within a shell script?

I have several projects that require me to change versions of Java/Grails/Maven. I'm trying to handle this with some scripts that would make the changes. For example: #!/bin/sh export JAVA_HOME=/...
28
votes
5answers
39k views

Parenthesis in expr arithmetic: 3 * (2 + 1)

expr does not seem to like parenthesis (used in mathematics to explicit operator priority): expr 3 * (2 + 1) bash: syntax error near unexpected token `(' How to express operator priority in bash?
18
votes
4answers
117k views

how to concatenate string variables into a third?

I need to concatenate two strings in bash, so that: string1=hello string2=world mystring=string1+string2 echo mystring should produce helloworld
10
votes
4answers
426 views

Run command after a certain length of time has elapsed?

If I'm executing a long process, is there any way I can execute some time-based commands? For example, I'm running a really long process which runs for roughly 10 minutes. After 5 minutes, I would ...
1
vote
1answer
394 views

Edit the editor in bash and other shells

Executing the fc builtin causes bash and other shells to fire up $FCEDIT on the last command. Because FCEDIT is a variable, this is inherently customizable. Is it possible to also customize the ...
0
votes
1answer
2k views

openSuse, not running the cron job

I have created a cron job in the /etc/cron.d/dispatchingEmail_I the permissions of dispatchingEmail_I are the following: -rw-r--r-- 1 root root 84 Sep 11 19:52 dispatchingEmail_I content of ...
1
vote
1answer
29 views

List names of aliases, functions and variables in zsh

I need a way to list the names (without the body/content/value) of aliases, functions, variables, arrays in zsh. Optimally its behave like compgen: compgen -a # will list all the aliases you could ...
1
vote
1answer
57 views

How do I rename files that have '|' in them?

I am using Fedora 24. I have tried many different ways to do this. I've tried it under a Windows VM with the folder in question as a shared folder. I've tried using the 'rename' command. I've ...
1
vote
1answer
70 views

Why is find not listing matching files when preceded by an asterisk(*)? [duplicate]

On Ubuntu 14.04, 64 bit, I have set /lib/modules/4.2.0-27-generic/kernel/drivers to be my current directory. I intend to search all files having net present as a sub-string. If I search with a regex ...
0
votes
2answers
94 views

How do I record all terminal input and output to a local file by default for each session?

I'm aware the script command can be used to record all keyboard input and screen output to a file, but this has to be invoked each time a terminal session is started. I keep timestamped versions of my ...
2
votes
1answer
53 views

How can I decompress and print the last few lines of a compressed text file?

I have 6 gzipped text files, each of which is ~17G when compressed. I need to see the last few lines (decompressed) of each file to check whether a particular problem is there. The obvious approach is ...
0
votes
2answers
84 views

Why is the default shell on my Ubuntu 14.04 bash?

Some said that Ubuntu 14.04's default shell is dash. Mine is bash. My /bin/sh is dash. I don't remember if I changed the default shell. What is some way to change the default shell? Can I find out ...
3
votes
2answers
72 views

confused with awk and shell variables

I am trying to run a script that uses awk. There is no error it seems, but it doesn't create the file that I want. This is the script: #!/bin/bash echo "Number of domain:" read number echo "Domain ...
-1
votes
1answer
44 views

for loop # usage

I am trying to understand how this piece of code works: for b in `git branch -r`; do git branch --track ${b##upstream/} $b; done In particular, the part where it does ${b##upstream/} I know it ...
2
votes
2answers
233 views

Play subtitles automatically with mpv

Subtitle files come in a variety of formats, from .srt to .sub to .ass and so on and so forth. Is there a way to tell mpv to search for subtitle files alongwith the media files and if it does to start ...
8
votes
4answers
1k views
60
votes
5answers
79k views

What does ` (backquote/backtick) mean in commands?

I came across the following command: sudo chown `id -u` /somedir and I wonder: what is the meaning of the ` symbol. I noticed for instance that while the command above works well, the one below ...
22
votes
1answer
2k views

Is there a way to redirect a program's output and still have it go to stdout?

Okay. If I wanted to redirect the output of a program to a file, I'd do something like this prog > file If I wanted to redirect both stdout and stderr to that file, then I'd do prog > file 2&...
4
votes
5answers
1k views

List files with line count and date

I want to be able to list files showing the number of lines the each file has and the date. I can happily get the line count using wc -l *. Not a problem. I can get the date using ls -l. Is there a ...
2
votes
2answers
69 views

Pass input file through pipe as argument?

I have two issues. I am trying to pass files through a pipe as an argument, and I am trying to use that file as a variable inside the sh function. Here is my command: find . -name 'segment*' | ...
1
vote
1answer
36 views

Formatting issue

I have a small script like below, where output gets highlighted (in red,yellow etc) on screen if there an issue normal=$(tput sgr0) red=$(tput setaf 1) yellow=$(tput setaf 3) df -h >/dev/null 2&...
-1
votes
2answers
35 views

Add another if condition

The following script is working fine. for i in `cat /app/scripts/symantec_scripts/list` do ssh root@$i "uname -n if [ -s /app/Symantec/virusdefs/definfo.dat ]; then cat /app/Symantec/virusdefs/...
0
votes
3answers
116 views

shell script - subtract 1 from hexadecimal mac address and add colons to it

I have mac address as 'C4:B9:83:7F:FF:AC' and I want to subtract 1 from its hex values which is C4B9837FFFAC so it will become C4B9837FFFAB and after this I again want to add colons to make it ...
-2
votes
2answers
9k views

How to delete a file in Arch console?

pacman stopped working and asked me to delete a file if "another package manager isn't working". What is the file for deleting files?
-4
votes
2answers
134 views

z in bash script returns zero [closed]

#[ -z "" ] #echo $? returns 0 #[ -a "" ] #echo $? returns 1 except z all other alphabets throw 1 What might be the reason?
10
votes
2answers
12k views

Printing decimal to ascii character, my command does not output as intended

I wanted to output a string of all the ascii characters with the following command for i in `seq 32 127`; do printf "%c" $i; done The output of the above command is: ...
14
votes
4answers
1k views

Escape sequences in output of script called from ncurses application

I'm currently running mcabber as my Jabber client (which uses ncurses) in a tmux session on my homeserver. Locally i run iTerm2 as a terminal emulator, which supports the triggering of growl ...
-1
votes
1answer
41 views

Is telnet/telnet-server a remote shell?

It is always said to use Secure Shell (SSH) instead of Telnet or rsh/rcp/rlogin, for security reason. SSH and rsh are both remote shells. I wonder if telnet is also a remote shell? If yes, why is it ...
1
vote
1answer
49 views

Better way to apply formula to specific column of inputfile, and pass-through all other columns as-is

I regularly need to apply simple formulas to input data give in textual tabular form. In the beginning, I wrote specific little functions for each use-case. Then I re-factored the "common code" into ...
4
votes
2answers
87 views

How Do I Remove Duplicate Words With Suffixes?

How do I compare a list of unsorted words of variable length and remove duplicate words that have a suffix? Example word list: iron curl curled railroad curler ...
1
vote
1answer
29 views

Different command outputs

I entered same command with a variable host. During 2nd time I entered blank space between host,= and $. Why it was trying to connect to a server ? Also, when I write like $(host name), I am getting ...
3
votes
3answers
30 views

When using popd, how to push the current directory onto the stack?

When using popd, how to push the current directory onto the stack?
1
vote
0answers
14 views

Wacom Linux xsetwacom Attach Shell Script to Buttons

Using Inutos Pro with Manjaro. Would like to attach a shell/bash script to one of eight buttons. Script would be something along the lines of 'dolphin Documents'. Can xsetwacom do this?
-1
votes
1answer
48 views

how to write own shell that works with ssh [closed]

I tried several tutorials I modified usermod -s shell path_to_binary username it does not work thru winscp, but works if use from Ubuntu terminal I want to own shell, where I can control over ...
0
votes
2answers
45 views

Out-putting the results of a nested for loop to a file in bash

I am new to bash and I have been attempting to create a file out of my loop in bash , I was successful in generating the file with the following code for ((i = 0; i <= 5; i++)); do for ((j = i; ...
0
votes
0answers
19 views

how to get a “parent-child” relationship with tmux panes and windows

Essentially I'm trying to mimic fork when I split a window or create a new one from an existing tmux session. For example lets say you enter a shell in gnome-terminal and then launch a new gnome-...
0
votes
3answers
61 views

How to pick oldest file in a folder from directory [duplicate]

I had n number of files are there in my ../in/ directory. From those files I want the oldest file to process and send it to the ../complete/ directory. The remaining files are sent to the ../error/ ...
3
votes
0answers
76 views

wait bash-builtin burns a CPU at 100 percent

Occurs at least on GNU bash version 4.3.42 x86_64 && GNU bash version 4.3.11 x86_64 I use sleep & wait $! instead of a simple sleep for getting an interruptible sleep by a signal (as ...
2
votes
2answers
97 views

Why is $ the default symbol for a user shell and # the default symbol for a root shell?

Operating a standard bash shell on a server, the PS1 prompt defaults to ending in a $ for non-root users, and # for root. IE: ubuntu@server:~$ sudo su root@server:/home/ubuntu# Why is this?
1
vote
2answers
10k views

How to remove a column or multiple columns from file using shell command?

My file, ARCHIVE B1_NAME B2_NAME B3_NAME ELEMENT INFO_NAM WERT PROCID -------- -------- -------- -------- -------- -------- ---- ------ ...