Questions tagged [bash]

The following description is intended for inquiries regarding scripts specifically crafted for the Bash command shell. Prior to submitting any questions or concerns here, please ensure that you have reviewed your shell scripts thoroughly using the comprehensive analysis tool available at https://shellcheck.net. For any queries relating to the practical application of Bash in an interactive manner, it is recommended to direct them to either Unix & Linux Newtab Q&A or Newtab Q&A, as they are more likely to be well-received in those communities compared to Newtab Q&A.

Can one install an npm package only if it has not already been installed?

Can the installation of an npm package be skipped if it is already installed? I am looking to streamline my tests on CircleCI, but every time I run npm install <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="ccbcbea3b8beadafb8a ...

What steps can I take to confirm that my cURL POST request is correctly executed in PHP?

I am faced with a challenge of handling a sample json object that contains specific data. My goal is to effectively store this information in a variable and then transmit it through a curl POST. $json = '{ "mac": "1234567890", "dns": "8.8.8.8 ...

Issue with opening a browser in BrowserSync using Bash on Ubuntu on Windows (Linux Subsystem)

When running browser-sync in Bash, I encounter an issue where the browser does not automatically open and instead displays the message [BS] Couldn't open browser (if you are using BrowserSync in a headless environment, you might want to set the open option ...

Run yarn/npm command depending on a predefined variable

I found this helpful bash script here that allows me to execute different commands based on whether a package.json script is called with or without a parameter... "scripts": { "paramtest": "if [ -z $1 ]; then echo "var is unset"; else echo "var is ...

Entrypoint Docker Script catering to the execution of either npm config, npm run, or both commands

When conducting tests with TestCafe and CucumberJS using Docker, which is built on top of Node.js, the test runs are initiated via npm scripts. The workflow includes... 1) Pulling a pre-built Docker image from Git 2) Optionally setting a 'config&apo ...

Running an SSH shell script through an npm command

Currently, I am working on developing an npm script to run an SSH shell command. The script currently utilizes an osascript command to open a Terminal window and execute the desired command. I am looking to update the script to make it execute the command ...

What is the process for utilizing the Google Chart API with curl command?

I am looking to create a bash script that can generate charts using the Google Chart API. Google Image Charts API will be discontinued in the future. Note: The Image Charts feature of Google Chart Tools was officially deprecated on April 20, 2012. It ...

Using HTML <style> in a bash script is a great way to enhance

I am attempting to eliminate the bullet points from HTML code generated by a bash script. I am currently struggling to apply the style across the entire program. Given my limited knowledge of html, I suspect that I may be misinterpreting or incorrectly p ...

Unable to locate the 'drizzle-orm' package within the Docker Container despite executing npm install in the Dockerfile

I set up all the dependencies in my Dockerfile using npm ci as shown below. Dockerfile FROM node:20-alpine AS base # 1. Install necessary dependencies FROM base AS deps RUN apk add --no-cache libc6-compat WORKDIR /app COPY package.json yarn.lock* packag ...

Incorporating sudo privileges within a makefile

Currently, I am situated behind a proxy in the realm of bash. My HTTP_PROXY and HTTPS_PROXY environment variables are set to the proxy. In order to successfully install something under sudo, such as pip, I must use the -E flag with sudo like this: sudo -E ...

The term 'eval' is not identified as an internal or external command, executable program, or batch file in the Windows npm script environment

$ npm run deploy:local > <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="b7d5d6d4dcd2d9d3f78799869987">[email protected]</a> deploy:local > eval "`aws-auth-helper ` lerna run deploy:sandbox --stream&quo ...

sed is not able to pick out the values

Looking for assistance with the sed command. I am trying to extract JSON values and assign them to variables using sed. Can someone provide guidance on how this can be achieved? For example: echo "{url:news.google.com,int:3}" | sed ? url=news.google.com ...

Parsing a multi-dimensional JSON object in Bash (az cli, azure) can be achieved by separating the object IDs using colons and converting them into an array

Exploring with jq and jmespath: I am intrigued by the objectId located in the middle of this string... I've attempted to use sed, regex, but there has to be a more clever solution... Command 1: az dls fs access show --account "$account" --path "$rootpath ...

A guide on utilizing jq to extract specific fields from a JSON string

Is there a way to extract specific fields from a JSON file using jq? On running 'jq '.node' out.json', the output contains the word 'null' This is the content of the file named out.json head out.json { "items": [ {"node":"aaaa-cn001.me.com","status":"s ...

How can we ensure the JSON output is easily searchable with grep?

The JSON structure I have is as follows: { "1":{ "state":{ "on":false, "bri":124, "hue":14985, "sat":252, "effect":"none", "xy":[ 0.5182, 0.4363 ], ...

Troubles encountered in transferring arguments from npm command line to package.json using a bash script

This is a different question compared to this particular thread. I am in search of the optimal method to input command line arguments into my package.json file and npm scripts without necessarily passing it directly into a script. While there are queries ...

How to organize the cpuinfo output in BASH

I'm currently working on a script that collects information from our servers and outputs the results to an HTML file. Everything is going smoothly up to a certain point. I've run into an issue when trying to grab the cpuinfo. While it does extract the data ...

Running a file in Windows CMD using Node is a simple process that involves executing specific

I have successfully executed this code snippet in Linux without any issues: > npm run setup-hooks -s > '.' is not recognized as an internal or external command, operable program or batch file. However, I am facing difficulties trying to m ...

The body parser is preventing the NODE from loading on localhost

var express = require('express'); var app = express(); var bodyParser = require('body-parser'); //ISSUE LINE **app.use(parser.json);** /////////////// var todos = []; var nextTodoItem = 1; app.use(bodyParser.json); ap ...

The application unexpectedly stopped running while using nodemon

Recently, I've been having trouble running a nodejs application in debug mode using Git Bash. While I've done it successfully several times before, the most recent attempts have not been working. When I enter the command: npm run startwindows:i ...

Is there a way to use jq to divide a JSON stream of objects into individual files according to the values of a specific object property?

Dealing with a hefty file (20GB+ compressed) named input.json, filled with a stream of JSON objects like so: { "timestamp": "12345", "name": "Some name", "type": "typea" } { "timestamp": "12345", "name": "Some name", "type": "typea ...

displaying results on a webpage

Is there a solution for displaying a Linux shell output on a web page that allows for continuous updating without needing to start and stop the process each time? I require a network analyzer tool based on a shell that can run continuously, similar to comm ...

Decoding the colors in the npm outdated output

When I run the git command npm outdated in bash on my Mac, I notice that the first four packages are printed in red. You can see the output in the image below. Does anyone have an explanation as to why these packages are highlighted in red? I suspect it ...

Issues with Pygame on MacOS X

Setting up Pygame on my MAC has been a challenge for me. My specifications include OS X El Capitan 10.11.4. Whenever I try to run a file with import pygame, I encounter the following error in terminal: ImportError: No module named 'pygame' Following the ...

Is there a way to redirect the results of the 'find' command into a pipeline that will trigger the execution of 'more' followed by 'grep' on the package.json file located two directories above?

I'm on a quest to identify the troublesome package.json file that is triggering a dependency warning. The warning originates from a sub-module, and I have employed a find command find . -name 'foo' to reveal its location. /a/very/very/very/long/path/to/a/ ...

Advantages of opting for npm instead of a shell program like Bash

Recently, I've delved into using npm (https://www.npmjs.com) and it's impressive how versatile it is as a build tool. However, as I explored further, I began to question its uniqueness. When you think about it, npm operates similar to a shell program (suc ...

Sending variables with spaces to the curl --data parameter

When dealing with arguments that contain spaces, it's important to note that they may not pass correctly to the curl command. Additionally, quotes might not be properly transferred in the --data field. For example, if I simply echo the variable &apos ...

Ways to transfer the results of a command as environmental variables to another command

I am seeking assistance with passing the output of my bash script as environment variables to an npm script. The current output of the bash script is: VAR1=test VAR2=test The goal is to use these variables in an npm script, specifically for running mocha ...

Having trouble globally installing express-generator using nvm

My current setup involves using NVM to bypass the need for utilizing sudo when installing global packages. This method successfully handles installations of tools like Bower and Grunt, but hits a snag when attempting to install Express Generator globally u ...

What is the best way to come to a halt after finishing a run?

Is it possible to stop a script in npm by running the command: npm run script Can I stop it using a command like this? npm stop script I attempted to do this, but it did not work as expected. I am aware that I can terminate it using "Ctrl + c", howeve ...

Execute a bash command using Appium

I have a bash script that deletes my temporary files after each test, ensuring a clean slate for the next one. Is there a way to run bash commands or execute a bash script using Appium at the end of every test? Currently, our tests are written in C# - id ...

Creating an Automated Backup Solution for Your Website using Bash/Shell Scripting

I am completely new to shell scripting and have been scouring the internet for guidance on how to create a backup script for my website. Unfortunately, I haven't been able to find anything that I can understand. I have a Synology Diskstation server a ...

The Mac system seems to be missing the gulp command -bash

Trying to install gulp on my Mac using the following commands: Is-iMac:~ itop$ npm root /Users/itop/node_modules Is-iMac:~ itop$ npm config set prefix /usr/local Is-iMac:~ itop$ npm root -g /usr/local/lib/node_modules Is-iMac:~ itop$ sudo npm install -g g ...

Transforming numerous key-value pairs into JSON formatting: utilizing sed in conjunction with an awk for loop

I am currently working with a data file that has 8 columns delimited by pipes. The last column contains an unpredictable number of key-value pairs, each separated by the equals sign and spaces between each pair. However, the challenge is that the values wi ...

Access the localhost:3000 webpage in kiosk mode once the Node.js server has fully started running

Currently, I am immersed in a Raspberry Pi project which requires me to operate a node server in kiosk mode. To prevent the default localhost opening upon server execution, I have implemented BROWSER=none. My intention is to use wait-on to ensure that th ...

Using Powershell to open a new terminal and execute a command in a bash session within WSL

Currently, I am in the process of creating a Powershell script to expedite setting up my development environment. My goal is to have multiple instances of WSL programs running on bash terminals. My objectives from within Powershell are as follows: Open a ...

A straightforward method to flatten and unflatten JSON files

I've managed to flatten JSON files effortlessly by executing this command in a combination of Node.js and Bash: npx flat foo.json > bar-flat-output.json. But now, I'm searching for another foolproof command that can easily undo the flattening process a ...

What is the best method for extracting a specific block of code from a json file with jq?

I have a json file called temp.json that looks like this: { "data": { "stuff": [ ..... ] }, "time": { "metrics": 83 } } I am looking to remove the following block of code from the JSON file: , ...

Leveraging the power of bash to execute a python script

I wrote a python script that takes a .txt file as input and produces another .txt file as output. My goal is to create a bash script that I can simply click on from my desktop to run the python script. This is what I have done so far: #!/bin/bash cd /Des ...

Getting rid of Node.js completely: the debate between automatic and manual removal

Recently, I followed this list of commands to completely remove node from my Linux Mint 18.1: sudo rm -rf /usr/local/lib/node* /usr/local/include/node* ~/.local/node* ~/.lib/node* ~/.include/node* /usr/local/bin/node* Alternatively, there is another solu ...

SyntaxError: JSON parsing error - encountered an unexpected character at the beginning

const express = require("express"); const bodyParser = require("body-parser"); const app = express(); const fs = require("fs"); app.use(bodyParser.urlencoded({ extended: true })); app.use(bodyParser.json()); // http://expressjs.com/en/starter/static-files ...

Running 'npm start' results in an error linked to package.json

Upon attempting to launch my React application with 'npm start', an error message appeared in the terminal: npm ERR! code ENOENT npm ERR! syscall open npm ERR! path /Users/louis/afrikalink/package.json npm ERR! errno -2 npm ERR! enoent ENOENT: no ...

The enchanting dance of words ceased as Poetry ran off with Worker.py, only to realize that the file b'/snap/bin/worker.py' was nowhere to be found in the directory

After running the command below in the same directory as the file worker.py: poetry run worker.py I encountered the following error in the terminal: me@LAPTOP-G1DAPU88:~/.ssh/workers-python/workers/composite_key/compositekey$ poetry run worker.py File ...

What is the best way to use cURL in a shell script to send a request with custom

When attempting to run a CURL statement, I successfully received the desired response: curl -s -POST --header 'Content-Type: application/json' 'http://www.dummy.com/projectname/page_relevance' -d '{"query": "q_string", "results": [{"abstract": "abs_string ...

While running a Conda command through a Node.js script with the use of PM2, I encountered an error stating "/bin/sh: 1: conda: not

Overview In the production environment, I am utilizing pm2 to run a nodejs server. The server executes a javascript file that triggers a python script using the conda run method. Unfortunately, an error occurs with the message: /bin/sh: 1: conda: not foun ...

Having trouble with N (Node Version Manager) post-installation - receiving error message "bash: n: command not found"

I am looking to handle node.js versions utilizing the n - node version manager. To install n, I followed the instructions on Github at https://github.com/tj/n and executed the following command in my terminal: sudo npm install -g n Upon entering my pass ...

Web user unable to execute binary file

I have encountered an issue with a php script that generates a shell script file which is executed as the user www-data. Most of the commands in the script run without any problems, but the last command involving a binary file fails to execute when the scr ...

Running the command with sudo does not yield any results, but it successfully executes after using "sudo su"

Upon trying to execute the command, I encounter a "command not found" error in my bash terminal: $ npm -v -bash: npm: command not found The same error occurs when using sudo: $ sudo npm -v sudo: npm: command not found However, running "sudo su" first a ...

What is the best way to indicate a 'yes' response when running an npm install in a Dockerfile?

I am working with a Dockerfile that looks like this: FROM node:latest RUN npm install something && \ npm install something && \ npm install something I am looking for a way to automatically pass 'yes' as the ...

Git bash encountered an error when attempting to run npm packages

When I run a project in my git bash, I encounter the following error message: ionic -v module.js:471 throw err; ^ Error: Cannot find module 'C:\Program Files\Git\node_modules\ionic\bin\ionic' at Functio ...

retrieve the source code from all .js links found within the document

There is a file labeled urls.txt. https://website.tld/static/main_01.js https://website.tld/static/main_02.js https://website.tld/static/main_03.js .... All the source code from every .js file in allsource.txt needs to be extracted. Instructions: To ge ...

Error encountered during Atom execution - The command '/usr/bin/env: 'node' was not found in the directory

Just starting out with coding on Atom and I'm stuck dealing with the same error message every time I try to run my Javascript code. bash: line 1: node: command not found /usr/bin/env: ‘node’: No such file or directory I've searched for solutions but ...

Having trouble with installing Typescript on a MacBook?

I have been attempting to follow the instructions provided on TypeScriptLang.org but for some reason, I am unable to successfully download typescript. This is what I have tried so far: mkotsollariss-MacBook-Pro:/ mkotsollaris$ which node /usr/local/bin/n ...

Global installation of NPM packages with CLI may result in encountering the error message "command not found"

This has happened to me twice in the past. The first time, I thought it was an issue with NPM, so I removed Node & NPM and stopped using the problematic package. I did a fresh installation and started working on another project. I installed the package (in ...

Script using PHP to remotely connect to a Linux server and run a Bash script

Currently, I am facing a challenge where I need to execute shell commands on our remote servers using PHP. The main goal is to install scripts through bash by having PHP execute these scripts on the server remotely. However, I have encountered an issue wh ...

Error: npm command is not recognized in the cPanel Terminal

When I attempt to write the following command: $ /usr/local/bin/node -v 14.17.3 I receive an error when using this command: $ node -v bash: node: command not found I tried the same approach with different commands, but it was unsuccessful: $ /usr/local/b ...

Setting custom parameters ($npm_config_) for npm scripts on Windows allows for more flexibility and customization in

I'm struggling with passing custom parameters from the command line to npm scripts in my package.json file. Despite researching on various platforms, including Stack Overflow, I haven't found a solution that works for me. Here's what I' ...

Adjust the JSON array format by adding new values to a particular key

I've been working on this code snippet: [ ["John Black",[ ["Lorem ipsum dolor sit amet.",27], ["Ut tempus lectus ut mi.",23] ]], ["Peter Pan",[ ["Quisque pulvinar odio.",22], ["Nec ut lorem quis inter ...

Extracting information from JSON files with jq when the key is a string of numbers

Recently, I've started using jq and ran into a problem when trying to parse my json data. The json is stored in a variable as shown below: temp='{ "1": { "my_name": "one" }, "2": { "my_name": "two" } }' My goal now is to extract the value of my_name for ...

Find the commands needed to install the specified npm global packages in a Bash environment

Is there a way to retrieve the list of globally installed npm packages without their dependencies using the command npm ls -g --depth=0? C:\Users\leon\AppData\Roaming\npm +-- <a href="/cdn-cgi/l/email-protection" class= ...

Husky: The pre-commit hook initiates the bash script, yet it does not pause for user input

Whenever I initiate a commit, the bash script starts running without waiting for user input .huskyrc file { "hooks": { "pre-commit": "bash scripts/pre_commit.sh" } } pre_commit.sh file #!/bin/bash PS3='Please enter your choice: ' opti ...

Could not locate the command "express" - perhaps it is not installed

I've tried multiple times to install Express, but all I get is the error mentioned in the title. Any assistance would be greatly appreciated. Here are the commands I have attempted. While my current directory is where I want the application to be located, ...

Retrieve lines from a document that fail to meet specific requirements

To tackle the issue, my goal is to extract lines from a file that do not contain the specific pattern: "ddd":[ The target is to filter out lines like "memo": { or "notice": "delivered on 17", and only retrieve lines containing "ddd":[, disregar ...

When iterating over every element in an array with jq

If I run the following command: kbc get pods -o=json | jq -c I will receive output like this: {"apiVersion":"v1","items":[{"name":"a"},{"name":"b"},{"name":"c"}]} Now, how can I access and display the name of each element in the items array? Would some ...

Certain relative paths are not functioning properly on macOS 10.15 Catalina beta version (19A471t)

When working with relative paths, I've noticed some peculiar behavior. Take for example: $ cd /Users $ ls -l ../bin ls: ../bin: No such file or directory $ ls -l /bin -r-xr-xr-x 1 root wheel 623344 31 May 08:33 bash -rwxr-xr-x 1 root wheel ...

Changing the name of identical files in numerous folders to a different title

I have 3 folders named FOLDER1, FOLDER2, and FOLDER3. Each folder contains files such as file1.txt, file2.txt, file3.txt, and so on. There are no subfolders within these directories. Some files in these folders are duplicates, for example: FOLDER1 has fi ...

I am attempting to enable automatic login in npm through a bash script, but I am unsure of how to input the username and password when prompted. Is there a way to achieve this?

I am currently working on a bash script to automate the installation of nodejs and setting up a private npm registry. So far, everything has been going smoothly until I encountered the following hurdle: Configuring the npm Registry: To set the npm regist ...

Tips for launching multiple copies of a Python script that utilizes the subprocess.call function

In my Python script job.py, I accept command-line arguments and use the subprocess package to run external programs sequentially. With a desire to simultaneously run four instances of this script, each with different arguments on my processor with 4 cores, ...

Can a script command be used to trigger a particular PHP function in a PHP file via a bash script?

The title of this question is pretty self-explanatory, but I'll provide some more details. There's a PHP file named hello-world.php and a bash script named testBash.sh in my setup. Inside hello-world.php, there are two methods: helloWorld() and ...

What is the process for taking individual files from a folder one by one, processing them, and then moving them to another folder?

I have a script written in Python called `cleaning_script.py` which is used to pre-process individual CSV files. Currently, I am running the script by executing this command in my Rstudio terminal: python3 cleaning_script.py file1.csv results_file1.csv. Th ...

Utilizing ANSI color codes in combination with jq

Exploring the integration of ANSI color codes with jq. Here are some test cases: $ echo '{"a":"b","c":"d"}' | jq -r .c d # Expected output $ echo '{"a":"b","c":"33[31md33[0m&q ...

Unexpected outcomes from executing the Bash and echo commands

My bash script is giving unexpected results when I run an echo command. Here's the code snippet causing the issue: echo "{ "outputs": { "result": "[{"directory":"mydir","somekey": ...

Retrieve the value from the initial element of the JSON array received from the GitAPI response within a shell script

I'm trying to retrieve the browser download URL for the latest release from a specific Git repository using the GitHub API. Sample command: curl -i https://api.github.com/repos/$owner/$repo/releases The response is in the form of a JSON array. Assuming ...

Obtain numerous JSON pages using jq

When making an API call, I receive a JSON response that can be formatted nicely using curl "https://mywebsite.com/api/cars.json&page=1" | jq '.' Displayed below is a sample of the output. Since there are multiple pages of data (112 total entries wi ...

Manipulate Json in jq with Shell Script

I am currently working on a shell script that updates specific values within a JSON array, which is stored in a separate file. The basic logic behind this script involves setting an environment variable called URL, pinging that URL, and then modifying the ...