Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [shell]

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, …). For shell scripts with errors, please check them in http://shellcheck.net before posting here.

0
votes
0answers
37 views

Shell script - directory size

I have to create a script that calculates the size of a directory given as an argument in bytes, like ./du.sh dir. Optionally I have 2 other arguments: ./du.sh dir 1000 files.txt, where 1000 stands ...
0
votes
1answer
15 views

rsync copy file without user and password less access

Please explain below mention command we are not passing username as well password still we can do rsync. rsync -avz rsync.apache.org::apache-dist /path/to/mirror
12
votes
2answers
619 views

What is the difference between the commands builtin cd and cd?

I encountered a Linux command, builtin cd. What is the difference between the commands builtin cd and cd? In fact, I made some researches about the difference, but I could not find a remarkable and ...
-1
votes
2answers
60 views

unix shell script - extracting result from two .txt files (time operation) [duplicate]

I have two text files. One file has startdatetime and second file have enddatetime. file 1 data(startdate-time): 2019-01-08 04:14:59 2019-01-08 04:16:57 file 2 data(enddate-time): 2019-01-08 04:15:...
0
votes
2answers
75 views

Creating a temporary file from standard input

Say I have a standard input stream of file contents and a command that expects a file name as an argument and I want to run that command on a file made up of the standard input stream’s file contents. ...
0
votes
1answer
29 views

When does the loop starting with while [ -n “$1” ]; executes?

I have a shell script with while loop starting with while [ -n "$1" ]; do I know that $1 refers to the argument right after the name of the script, ie firstargument, when I execute ./myscript.sh ...
0
votes
0answers
23 views

Menus and Return commands in Shell; Stuck in a loop

I have a menu that uses the case command to switch to a sub-menu that then calls to a shell script (.functions) as follows: . .functions loop=z while [ "$loop" = z ] do clear tput cup 3 12; echo "...
-1
votes
1answer
20 views

How to write a script to kill & clean the resources of executing process?

I have an application running in c language (my_process.c) and a script (stop_process.sh) to stop the application and clean up all resources held by the process. In the application code, let's say I ...
0
votes
1answer
47 views

what does >& mean in a shell command?

I actually have 2 questions: What does >& mean in a shell script as in /usr/bin/x_app >& /tmp/blog.txt? Shouldn't a number follows & to make it a stdout/err thing? As far as I know ...
4
votes
2answers
325 views

The files with the extension bash and sh

I made some researches about the files with bash and sh extensions. Most of the people and resources say that if a file has bash extension, then it contains bash scripts. Likewise, the file with sh ...
0
votes
0answers
6 views

Use Mimeopen to configure default applications

I don't have any gui file manager installed and I want to use nnn file manager. NNN uses mimeopen and xdg-open to open files. I can't seem to figure out how to configure any of them. I know about ...
0
votes
1answer
53 views

Can't login as user

Everything works as root. I can startx, and get into iceWM. I'll be using i3, but that works aswell through lightdm if I login as "other" then write "root". Loging in in a TTY works aswell, but only ...
-2
votes
2answers
51 views

How can i move all files and dir within a dir to its sub dir

Here is the directory listing, Parent dir is B, i want to move/copy C, D and filetest.txt to dir E. How can i do that with a single command.
-2
votes
0answers
47 views

Whenever I open shell it print command not found [on hold]

Whenever I open a new tab or new window I see the following error in the console bash: 4e3291fa48f43adebb522c3c91f49c3120d927525994a34052bee83fb15b55f9: command not found bash: ...
1
vote
2answers
47 views

Copy a folder overwriting ONLY smaller files in destination

I have tons of PDFs in multiple sub-folders in /home/user/original that I have compressed using ghostscript pdfwrite in /home/user/compressed. ghostscript has done a great job at compressing about 90% ...
0
votes
0answers
19 views

Command to print most recent JOBID in LSF in Linux?

In bash shell, I used awk with awk '{print $1}' . Ihave tried in the for loop and my code in the shell script as below; for i in `cat $test_list_file` ...
0
votes
1answer
32 views

rsync not quitting and running next rsync

I have a shell script that has 6 rsync commands. What it should do is run the first and then move on to the next. However, what it does right now is do the first once it is finished it'll hang and ...
1
vote
1answer
39 views

What characters need to be escaped when using the printf command?

I want to clarify that I am not talking about how to escape characters on the shell level of interpretation. As far as I can tell, only two character need to be escaped: % and \ To print a literal %,...
0
votes
1answer
31 views

[1]+ Exit 125 nohup [on hold]

I am running the following command: nohup ./run_hyper_param_tuning.sh> ../../logs/hyper_model_15_b_Jan.txt 2>&1 & echo $! >save_pid.txt It has been always working but suddenly it ...
0
votes
0answers
14 views

How to create separate files based on first column value? [duplicate]

It is tab separated 3 column file. I need to create separate files based on first column value Input: 194501 CAD 1.47421052631579 194517 CAD 1.39578947368421 194520 CAD 0.949473684210526 194501 ...
10
votes
1answer
392 views

Usage of enclosing braces {} as arguments to commands and their options

Examples I've recently found examples of using pairs of enclosing braces {}, with nothing in between the opening and closing braces, as arguments to commands and even to their options: cat foo | ...
1
vote
1answer
61 views

How to pass variable from one function to another function

updateEnvironmentField() { linewithoutquotes=`echo $LINE | tr -d '"'` b() } I want to pass variable named $linewithoutquotes to another method called b(), which is called from ...
-1
votes
0answers
13 views

Save Linux conf / command-steps to fully configured system (Logging + Bash Installation script) [on hold]

I would like to use Linux again. Void Linux would be my operating system of Choice. Tried Slack Linux, ArchLinux, Debian/Raspbian and a little bit Ubuntu. I'm using Win10 and I think, it will be ...
-6
votes
1answer
46 views

bash loop all files in directory, then loop lines of each file

I have urls1.txt urls2.txt urls3.txt And so on. How can I loop all files in this directory then loop each line of these files?
1
vote
2answers
37 views

Error while trying to compress pdf using ghostscript recursively via loop

I intend to compress a few thousand PDF files in a folder recursively. I tried with following loop: #!/bin/bash find "/home/user/original" -type f -name *.pdf | while read -r file do gs -sDEVICE=...
0
votes
2answers
33 views

Why does zsh list my prompt incorrectly on OS X?

I'm trying to figure out why zsh's prompt looks like this: (in text form): \[\]\u\[\] at \[\]\h\[\] in \[\]\w\[\]$(__git_ps1) \[\]$(git_diff)\n\[\]($(date +'1:MikesMBP.local ')) \[\]$\[\] I'd like ...
0
votes
0answers
30 views

Raising permissions of account “dummy” when executing command from “root” as “dummy”?

Context: While trying to execute command su a -c task as user dummy when being logged (with sudo su in as root on Ubuntu 16.04, I receive the following error message: root@DESKTOP-344ab:/home/dummy#...
1
vote
1answer
34 views

apt - How disable the fetching of the Contents files?

When apt update I want to avoid download all tthe contents.gz files to spare time and network resources. How could this be done with command line options nor configuration files?
3
votes
1answer
207 views

Recursive shell script to list files

I'm trying to write a shell script that lists certain types of files in a Directory (and sub-directories). I'm struggling with the recursive part. Here's what I have: #!/bin/sh #download dir ...
2
votes
2answers
224 views

I'm not getting cube of the number

while [ "$c" = y -o "$c" = Y -o -z $c ] do echo enter a number; read n; if [ $n -ge 0 -a $n -le 50 ];then echo "cube= `expr $n * $n * $n`"; fi; echo y to continue or any to exit; ...
-1
votes
0answers
32 views

How to get JobID of each LSF Pending Jobs in Linux

I want to get jobId for each pending jobs using below command; JOBID=`bjobs -w | grep 'PEND' | awk $1` The above trial is not ...
-17
votes
0answers
58 views

A Exam Question [closed]

Write Script to find out biggest number from given three numbers. Numbers are supplies as command line argument. Print error if sufficient arguments are not supplied.
0
votes
1answer
34 views

Output string to log file, then pipe to function as argument

So I am trying to echo a string out to a log file and also pass that echo'd string over to a function along with other arguments as well. I can't seem to figure out how to do it or find any answers on ...
2
votes
1answer
67 views

Why doesn't ctrl+u send SIGKILL? stty says it should

I can interrupt a program by pressing ctrl+c in the shell. Often this kills the program but some programs trap the signal and keep running. I want to be able to kill such programs more aggressively ...
1
vote
4answers
48 views

How to extract a value from json response using shell script

{"expand":"renderedFields,names,schema,operations,editmeta,changelog,versionedRepresentations","id":"15114","self":"https://brg-jira-tst.state.mi.us/rest/api/2/issue/15114","key":"BRGTEST-11","fields":...
1
vote
2answers
83 views

List of shells support `local` keyword for defining local variables

I know that Bash and Zsh support local variables, but there are systems only have POSIX-compatible shells. And local is undefined in POSIX shells. So I want to ask which shells support local keyword ...
0
votes
0answers
84 views

Does anyone remember “wow”?

Is there anyone out there who remembers the "wow" command? This is my recollection: Back in the days- oh, probably around or before BSD 4.3 (circa 1984-88 or so)- you could type in "wow" at the ...
0
votes
0answers
48 views

Remove Partial Duplicates in Shell Scripting

831177 830372 831177 830373 831178 831177 831178 831177 830373 830372 831958 827391 832226 824442 834434 833887 I've first line combination in 4th line and 2nd line also in 4th line I want the ...
1
vote
0answers
19 views

Command to list all reserved words [duplicate]

Is there a command to list all reserved words? I'm aware of resources such as the GNU reserved word index, but what I'm looking for is a command that gives me this information for my shell on the ...
0
votes
1answer
25 views

How to execute command under if statement in Shell Script under expect condition?

send "if [ `ps -ef | grep ttyS1 | sed -n 1p | cut -d ' ' -f 2` -eq 'ttyS1' ]; then not_found='false' else not_found='true' fi\r" I have tried so many time with double quote and single quote also ...
0
votes
2answers
76 views

Is the behavior of escaping special characters inside double-quotes in mainstream POSIX-compliant shells at odds with POSIX?

Per the POSIX Shell Command Language Page: \ The <backslash> shall retain its special meaning as an escape character (see Escape Character (Backslash)) only when followed by one of the ...
0
votes
1answer
21 views

/.zshrc:export:97: not valid in this context -w: not sure what this means?

when I open up my terminal in Mac OS, the terminal prints at the top /.zshrc:export:97: not valid in this context -w I modified a line in my /.zshrc file by following strict instructions online ...
2
votes
2answers
60 views

“Command not found” when using ssh and non absolute commands

I want to use a command over ssh: ssh myuser@myhost mycommand but doing so I always get: sh: mycommand: command not found using following obviously works: ssh myuser@myhost /usr/local/bin/...
0
votes
2answers
24 views

Repeat command execution attempts until status is not specific, preserve data

I have a case where a first few command execution attempts after daemon restart are returning 2 (followed by stderr messages), than everything works correctly. In order to bypass this bug I've come ...
2
votes
2answers
157 views

How to remove “exit” command from Linux shell

I am working on Linux Ubuntu 16.04. In this challenge I want to remove some commands from the Linux shell. Specifically, I want to remove the exit command. I want that if a user will try to exit ...
3
votes
2answers
91 views

Should the shell read (an script) one character at a time?

While reading an script, the shell will read the script from a file, or from a pipe or possibly, some other source (stdin ?). The input may not be seek able under some corner conditions (no way to ...
2
votes
1answer
41 views

How can I grep for empty functions?

I'm recursively looking in a directory for all functions containing only a blank one-line comment, such as the following: public function index() { // } I tried grep -PR "//$" * with no luck.
-1
votes
0answers
28 views

Updating the score based on the number attempts of the player

I need to change the score of player in this game and it depenent on the tries that the player make if he guessed write in the first try he gets 3 point and 2 for the second and 1 for the lash try ,...
1
vote
1answer
28 views

Listing content from two directories with wildcard

I have a task to list all files from /bin and /usr/bin that contain an e that is neither at the beginning nor at the end. The wildcard is [!e]*e*[!e] and works. (Tested commands cd /bin & ls -l [!...
2
votes
4answers
91 views

Variable in Date command

I want to use a variable inside date command . GNU date is not supportable in my system. I use Sunos and when I use date with -d option it is shwoing -d as bad substitution. #!/usr/bin/ksh ...