Вопрос задан 07.10.2023 в 04:57. Предмет Информатика. Спрашивает Бутманов Данил.

Два скрипта . Линукс 1)Create script using pico which will output the number of days passed since

the beginning of the year. 2)Create script which will ask user to provide a value and then, according to the value provided: 1 - set some environmental variable 2 - output this environmental variable 3 - erase this environmental variable 4 - exit without errors Any other - exit with error
0 0
Перейти к ответам

Ответы на вопрос

Внимание! Ответы на вопросы дают живые люди. Они могут содержать ошибочную информацию, заблуждения, а также ответы могут быть сгенерированы нейросетями. Будьте внимательны. Если вы уверены, что ответ неверный, нажмите кнопку "Пожаловаться" под ответом.
Отвечает Муравьёва Ксения.

Ответ:

Объяснение:

1:

#!/usr/bin/env bash

echo date '+%j'

2: Нужна переменная сессионная или именно что окружения для всех?

#!/usr/bin/env bash

echo "Введите слово";

read Var1;

echo $Var1;

unset Var1;

exit 0;

0 0
Отвечает нейросеть ChatGpt. Будьте внимательны, ответы нейросети могут содержать ошибочные или выдуманные данные.

Here are two Linux shell scripts to accomplish the tasks you described:

  1. Create a script to calculate the number of days passed since the beginning of the year:
bash
#!/bin/bash # Get the current date in the format YYYY-MM-DD current_date=$(date +%F) # Extract the year and day of the year from the date year=$(date -d "$current_date" +%Y) day_of_year=$(date -d "$current_date" +%j) # Calculate the number of days passed since the beginning of the year days_passed=$((day_of_year)) echo "Number of days passed since the beginning of the year in $year: $days_passed"

Save this script as, for example, days_passed.sh, and make it executable with chmod +x days_passed.sh. You can run it with ./days_passed.sh.

  1. Create a script to handle user input for setting, outputting, or erasing an environmental variable:
bash
#!/bin/bash echo "Enter a choice:" echo "1 - Set an environmental variable" echo "2 - Output an environmental variable" echo "3 - Erase an environmental variable" echo "4 - Exit without errors" echo "Any other - Exit with an error" read choice case $choice in 1) echo "Enter the name of the environmental variable:" read var_name echo "Enter the value for $var_name:" read var_value export "$var_name=$var_value" echo "Environmental variable $var_name set to $var_value" ;; 2) echo "Enter the name of the environmental variable to output:" read var_name echo "$var_name=${!var_name}" ;; 3) echo "Enter the name of the environmental variable to erase:" read var_name unset "$var_name" echo "Environmental variable $var_name erased" ;; 4) echo "Exiting without errors." exit 0 ;; *) echo "Error: Invalid choice." exit 1 ;; esac

Save this script as, for example, env_variable_manager.sh, and make it executable with chmod +x env_variable_manager.sh. You can run it with ./env_variable_manager.sh.

These scripts should fulfill the tasks you outlined.

0 0

Похожие вопросы

Топ вопросов за вчера в категории Информатика

Последние заданные вопросы в категории Информатика

Задать вопрос